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3 2 3 3 1
0
9 11
1 9
3 1
1 2
2 3 
2 4
4 5
5 6
6 4
7 8
8 7
8 9

4 1
2 3


0
#include 
#include 
#include 
#include 
#include 

using namespace std;

typedef pair ii;
typedef vector vii;
typedef vector vi;

#define s(n) scanf("%d",&n)
#define N 10005
#define REP(i,a,b)\
		for(int i = a ; i < b ; ++i)

vi gr[N],grTr[N];
bool visited[N] , res[N] ;
int level[N],CComp[N];
stack stk;

void dfs1(int n)
{
	visited[n] = true;
	REP(i,0,gr[n].size())
	   if(!visited[gr[n][i]])
	      dfs1(gr[n][i]);
	stk.push(n);
}

void dfs2(int n , int scc)
{
	visited[n] = false ;
	CComp[n] = scc;                   //give single value to all vertices of strongly connected component
	REP(i,0,grTr[n].size())
	    if(visited[grTr[n][i]])
	       dfs2(grTr[n][i],scc);
}

int main()
{
	int v,e,i,j,k,t;
	while(1)
	{
		s(v);
		if(v==0) break;
		s(e);
		REP(k,0,e)
		{
			s(i);s(j);
			gr[i].push_back(j);
			grTr[j].push_back(i);
		}
		
		REP(i,1,v+1)
		   if(!visited[i])
		      dfs1(i);
            
		int scc = 0;      
		while(!stk.empty())
		{
		   if(visited[stk.top()])
		   {
		   	   dfs2(stk.top(),++scc);
		   	   res[scc] = true;         // initially mark all scc are sink components
		   	   stk.pop();
		   }
		  else  stk.pop();
		}
		
		REP(i,1,v+1)
		   REP(j,0,gr[i].size())
            {
            if(CComp[i] != CComp[gr[i][j]])  // vertex i has edge to other scc i.e (scc having i)-->(other scc) => scc having i is parent not sink component
		   	      res[CComp[i]] = false ;
        }

		REP(i,1,v+1)
		    if(res[CComp[i]])
		       printf("%d ",i);
		printf("\n");
		
        REP(i,0,v)             
            {
            gr[i].clear();       // removes elements of container for next test case
            grTr[i].clear();
        }
	}
	return 0;
}
6 6
1 2
2 3
3 4
4 5
5 6
6 1

0
8 9
1 2
2 3
3 4
4 5
5 6
6 1

1 7
7 8 
8 3

1 1
1 1

9 11
1 9
3 1
1 2
2 3 
2 4
4 5
5 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