



'''simple docstring'''





from __future__ import annotations

def 	a_					(							_lowerCAmelCase	)				->				int:
  global graph, reversed_graph, scc, component, visit, stack
  if visit[u]:
    return
  __lowerCamelCase	:	int   	=			True
  for v in graph[u]:
    dfs(__UpperCamelCase	)
  stack.append(__UpperCamelCase	)

def 	a_					(							_lowerCAmelCase	)				->				Optional[int]:
  global graph, reversed_graph, scc, component, visit, stack
  if visit[u]:
    return
  __lowerCamelCase	:	List[Any]   	=			True
  component.append(__UpperCamelCase	)
  for v in reversed_graph[u]:
    dfsa(__UpperCamelCase	)

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


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

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

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










'''simple docstring'''





import math
from timeit import timeit

def 	a_					(							_lowerCAmelCase	)				->				int:
  __lowerCamelCase	:	int   	=			0
  __lowerCamelCase	:	Optional[int]   	=			abs(_lowerCAmelCase	)
  while True:
    __lowerCamelCase	:	List[str]   	=			n // 10
    digits += 1
    if n == 0:
      break
  return digits

def 	a_					(							_lowerCAmelCase	)				->				int:
  return 1 if n == 0 else math.floor(math.log(abs(_lowerCAmelCase	)	,10	) + 1	)

def 	a_					(							_lowerCAmelCase	)				->				int:
  return len(str(abs(_lowerCAmelCase	)	)	)

def 	a_					(							)				->				None:
  from collections.abc import Callable

  def benchmark_a_function(_lowerCAmelCase	,_lowerCAmelCase	) -> None:
    __lowerCamelCase	:	Any   	=			F'{func.__name__}({value})'
    __lowerCamelCase	:	int   	=			timeit(F'__main__.{call}'	,setup='import __main__'	)
    print(F'{call}: {func(_lowerCAmelCase	)} -- {timing} seconds'	)

  for value in (262144, 1125899906842624, 1267650600228229401496703205376):
    for func in (num_digits, num_digits_fast, num_digits_faster):
      benchmark_a_function(_lowerCAmelCase	,_lowerCAmelCase	)
    print()


if __name__ == "__main__":
   import doctest

   doctest.testmod()
   benchmark()






