





from __future__ import annotations

from collections import deque
from queue import Queue
from timeit import timeit

UpperCAmelCase						:       Union[str, Any]        =					{
    '''A''': ['''B''', '''C'''],
    '''B''': ['''A''', '''D''', '''E'''],
    '''C''': ['''A''', '''F'''],
    '''D''': ['''B'''],
    '''E''': ['''B''', '''F'''],
    '''F''': ['''C''', '''E'''],
}







def 			_SCREAMING_SNAKE_CASE    (       a ,						a  )				->				list[str]:
					__A     :						List[str]          =    {start}
					__A     :						str          =    [start]
					__A     :						Queue          =    Queue()
					queue.put(a  )
					while not queue.empty():
										__A     :						Optional[int]          =    queue.get()
										for w in graph[v]:
															if w not in explored:
																				explored.add(a  )
																				result.append(a  )
																				queue.put(a  )
					return result







def 			_SCREAMING_SNAKE_CASE    (       a ,						a  )				->				list[str]:
					__A     :						Optional[int]          =    {start}
					__A     :						List[str]          =    [start]
					__A     :						Optional[int]          =    deque([start]  )
					while queue:
										__A     :						List[str]          =    queue.popleft()
										for child in graph[v]:
															if child not in visited:
																				visited.add(a  )
																				result.append(a  )
																				queue.append(a  )
					return result







def 			_SCREAMING_SNAKE_CASE    (       a  )				->				None:
					__A     :						int          =    F"""from __main__ import G, {name}"""
					__A     :						Tuple          =    1_00_00
					__A     :						Any          =    timeit(F"""{name}(G, 'A')""" ,						setup=a ,						number=a  )
					print(F"""{name:<35} finished {number} runs in {res:.5f} seconds"""  )


if __name__ == "__main__":
				import doctest

				doctest.testmod()

				benchmark_function('''breadth_first_search''')
				benchmark_function('''breadth_first_search_with_deque''')
				# breadth_first_search                finished 10000 runs in 0.20999 seconds
				# breadth_first_search_with_deque     finished 10000 runs in 0.01421 seconds











from __future__ import annotations







def 			_SCREAMING_SNAKE_CASE    (       a  )				->				List[str]:
					global graph, reversed_graph, scc, component, visit, stack
					if visit[u]:
										return
					__A     :						List[Any]          =    True
					for v in graph[u]:
										dfs(a  )
					stack.append(a  )







def 			_SCREAMING_SNAKE_CASE    (       a  )				->				Optional[Any]:
					global graph, reversed_graph, scc, component, visit, stack
					if visit[u]:
										return
					__A     :						str          =    True
					component.append(a  )
					for v in reversed_graph[u]:
										dfsa(a  )







def 			_SCREAMING_SNAKE_CASE    (       )				->				Optional[int]:
					global graph, reversed_graph, scc, component, visit, stack
					for i in range(a  ):
										dfs(a  )
					__A     :						str          =    [False] * n
					for i in stack[::-1]:
										if visit[i]:
															continue
										__A     :						Optional[Any]          =    []
										dfsa(a  )
										scc.append(a  )
					return scc


if __name__ == "__main__":
				# n - no of nodes, m - no of edges
				UpperCAmelCase  ,			UpperCAmelCase						:       List[str]        =					list(map(int, input().strip().split()))

				UpperCAmelCase						:       list[list[int]]        =					[[] for _ in range(n)]  # graph
				UpperCAmelCase						:       list[list[int]]        =					[[] for i in range(n)]  # reversed graph
				# input graph data (edges)
				for _ in range(m):
								UpperCAmelCase  ,			UpperCAmelCase						:       int        =					list(map(int, input().strip().split()))
								graph[u].append(v)
								reversed_graph[v].append(u)

				UpperCAmelCase						:       list[int]        =					[]
				UpperCAmelCase						:       list[bool]        =					[False] * n
				UpperCAmelCase						:       list[int]        =					[]
				UpperCAmelCase						:       list[int]        =					[]
				print(kosaraju())




