






from __future__ import annotations

from collections import Counter
def        UpperCAmelCase      (   _lowercase      ):


    '''simple docstring'''



    _lowercase     =	[True] * n
    _lowercase     =	False
    _lowercase     =	False
    _lowercase     =	True

    for i in range(3,      int(n**0.5 + 1      ),      2      ):
        _lowercase     =	i * 2
        while index < n:
            _lowercase     =	False
            _lowercase     =	index + i

    _lowercase     =	[2]

    for i in range(3,      _lowercase,      2      ):
        if is_prime[i]:
            primes.append(_lowercase      )

    return primes
def        UpperCAmelCase      (   _lowercase      ):


    '''simple docstring'''



    _lowercase     =	str(_lowercase      )
    _lowercase     =	[]
    _lowercase     =	['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']

    for duplicate in Counter(_lowercase      ) - Counter(set(_lowercase      )      ):
        _lowercase     =	[int(number_str.replace(_lowercase,      _lowercase      )      ) for digit in digits]
        replacements.append(_lowercase      )

    return replacements
def        UpperCAmelCase      (   _lowercase = 8      ):


    '''simple docstring'''



    _lowercase     =	set()

    # Filter primes with less than 3 replaceable digits
    _lowercase     =	{
        x for x in set(prime_sieve(1000000      )      ) if len(str(_lowercase      )      ) - len(set(str(_lowercase      )      )      ) >= 3
    }

    for prime in primes:
        if prime in numbers_checked:
            continue

        _lowercase     =	digit_replacements(_lowercase      )

        for family in replacements:
            numbers_checked.update(_lowercase      )
            _lowercase     =	primes.intersection(_lowercase      )

            if len(_lowercase      ) != family_length:
                continue

            return min(_lowercase      )

    return -1


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








from __future__ import annotations
def        UpperCAmelCase      (   _lowercase      ):


    '''simple docstring'''



    global graph, reversed_graph, scc, component, visit, stack
    if visit[u]:
        return
    _lowercase     =	True
    for v in graph[u]:
        dfs(_lowercase      )
    stack.append(_lowercase      )
def        UpperCAmelCase      (   _lowercase      ):


    '''simple docstring'''



    global graph, reversed_graph, scc, component, visit, stack
    if visit[u]:
        return
    _lowercase     =	True
    component.append(_lowercase      )
    for v in reversed_graph[u]:
        dfsa(_lowercase      )
def        UpperCAmelCase      (   ):


    '''simple docstring'''



    global graph, reversed_graph, scc, component, visit, stack
    for i in range(_lowercase      ):
        dfs(_lowercase      )
    _lowercase     =	[False] * n
    for i in stack[::-1]:
        if visit[i]:
            continue
        _lowercase     =	[]
        dfsa(_lowercase      )
        scc.append(_lowercase      )
    return scc


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

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

   lowerCamelCase										=  []
   lowerCamelCase										=  [False] * n
   lowerCamelCase										=  []
   lowerCamelCase										=  []
   print(kosaraju())
