

from __future__ import annotations





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





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





def 	snake_case_      ()			->	List[str]:
   global graph, reversed_graph, scc, component, visit, stack
   for i in range(__A     ):
      dfs(__A     )
   __lowerCAmelCase  :			Tuple					    =						[False] * n
   for i in stack[::-1]:
      if visit[i]:
         continue
      __lowerCAmelCase  :			Tuple					    =						[]
      dfsa(__A     )
      scc.append(__A     )
   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'''
def 				snake_case_  (   a__		:	int			):



    """simple docstring"""




    if not isinstance(a__    ,a__			) or number < 0:
        raise ValueError("""Input must be a non-negative integer"""			)

    __lowercase							=						number & ~(number - 1)
    __lowercase							=						0
    while intermediate:
        intermediate >>= 1
        index += 1
    return index - 1


if __name__ == "__main__":
  import doctest

  doctest.testmod(verbose=True)




