





from itertools import permutations







def 			_SCREAMING_SNAKE_CASE    (       a = 5  )				->				int:
					if gon_side < 3 or gon_side > 5:
										raise ValueError('gon_side must be in the range [3, 5]'  )

					# Since it's 16, we know 10 is on the outer ring
					# Put the big numbers at the end so that they are never the first number
					__A     :						int          =    list(range(gon_side + 1 ,						0 ,						-1  )  )
					__A     :						Dict          =    list(range(gon_side + 2 ,						gon_side * 2 + 1  )  )

					for perm in permutations(small_numbers + big_numbers  ):
										__A     :						Union[str, Any]          =    generate_gon_ring(a ,						list(a  )  )
										if is_magic_gon(a  ):
															return int(''.join(str(a  ) for n in numbers  )  )

					__A     :						Any          =    F"""Magic {gon_side}-gon ring is impossible"""
					raise ValueError(a  )







def 			_SCREAMING_SNAKE_CASE    (       a ,						a  )				->				list[int]:
					__A     :						str          =    [0] * (gon_side * 3)
					__A     :						Union[str, Any]          =    perm[0:3]
					perm.append(perm[1]  )

					__A     :						List[Any]          =    1 if gon_side < 5 else 2

					for i in range(1 ,						len(a  ) // 3 + magic_number  ):
										__A     :						List[str]          =    perm[2 * i + 1]
										__A     :						List[str]          =    result[3 * i - 1]
										__A     :						Optional[Any]          =    perm[2 * i + 2]

					return result







def 			_SCREAMING_SNAKE_CASE    (       a  )				->				bool:
					if len(a  ) % 3 != 0:
										raise ValueError('a gon ring should have a length that is a multiple of 3'  )

					if min(numbers[::3]  ) != numbers[0]:
										return False

					__A     :						Any          =    sum(numbers[:3]  )

					return all(sum(numbers[i : i + 3]  ) == total for i in range(3 ,						len(a  ) ,						3  )  )


if __name__ == "__main__":
				print(solution())











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())




