public static void main(String[] args){
		
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		ArrayList<ArrayList<Integer>> g = new ArrayList<ArrayList<Integer>>();
		boolean[] visited = new boolean[n+1];
		for(int i=0;i<=n;i++){
			g.add(new ArrayList<Integer>());
			visited[i]=false;
		}
		for(int j=0;j<m;j++){
			int a = in.nextInt();
			int b = in.nextInt();
			g.get(a).add(b);
		}
		
		
		for(int i=1;i<=n;i++){
			dfs(i, g, visited);
		}
	}