

"""simple docstring"""




import sys

sys.set_int_max_str_digits(0)  # type: ignore
def   __SCREAMING_SNAKE_CASE		(		lowercase__ ):
					"""simple docstring"""
					A     =   [0] * 11
					A     =   [0] * 11

					# mark last 9 numbers
					for _ in range(9 ):
										A     =   1
										A     =   number // 10
					# flag
					A     =   True

					# check last 9 numbers for pandigitality

					for x in range(9 ):
										if not check_last[x + 1]:
															A     =   False
					if not f:
										return f

					# mark first 9 numbers
					A     =   int(str(lowercase__ )[:9] )

					for _ in range(9 ):
										A     =   1
										A     =   number // 10

					# check first 9 numbers for pandigitality

					for x in range(9 ):
										if not check_front[x + 1]:
															A     =   False
					return f
def   __SCREAMING_SNAKE_CASE		(		lowercase__ ):
					"""simple docstring"""
					A     =   [0] * 11

					# mark last 9 numbers
					for _ in range(9 ):
										A     =   1
										A     =   number // 10
					# flag
					A     =   True

					# check last 9 numbers for pandigitality

					for x in range(9 ):
										if not check_last[x + 1]:
															A     =   False
					return f
def   __SCREAMING_SNAKE_CASE		(		):
					"""simple docstring"""
					A     =   1
					A     =   1
					A     =   2
					# temporary Fibonacci numbers

					A     =   1
					A     =   1
					A     =   2
					# temporary Fibonacci numbers mod 1e9

					# mod m=1e9, done for fast optimisation
					A     =   [0] * 1_000_000
					A     =   1_000_000_000

					for x in range(1_000_000 ):
										A     =   (aa + ba) % m
										A     =   ba % m
										A     =   ca % m
										if checka(lowercase__ ):
															A     =   1

					for x in range(1_000_000 ):
										A     =   a + b
										A     =   b
										A     =   c
										# perform check only if in tocheck
										if tocheck[x + 3] and check(lowercase__ ):
															return x + 3  # first 2 already done
					return -1


if __name__ == "__main__":
	print(f"""{solution() = }""")







from __future__ import annotations






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






def     lowerCamelCase__				(   a ) ->  List[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     lowerCamelCase__				(   ) ->  str:
   global graph, reversed_graph, scc, component, visit, stack
   for i in range(a ):
      dfs(a )
   _A:    Optional[Any]						     =			[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__						:	Any	     = 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__						:	str	     = 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())



