




from __future__ import annotations

def 	lowerCAmelCase_	(     lowerCamelCase:				Any  )    ->	Any:


      '''simple docstring'''




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

def 	lowerCAmelCase_	(     lowerCamelCase:				Optional[int]  )    ->	str:


      '''simple docstring'''




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

def 	lowerCAmelCase_	(     )    ->	List[str]:


      '''simple docstring'''




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


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

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

      __SCREAMING_SNAKE_CASE			:      List[Any]      			=[]
      __SCREAMING_SNAKE_CASE			:      List[str]      			=[False] * n
      __SCREAMING_SNAKE_CASE			:      Dict      			=[]
      __SCREAMING_SNAKE_CASE			:      Optional[Any]      			=[]
      print(kosaraju())


import importlib.metadata
import subprocess
import sys





def 	snake_case_      (__A     :						bool = False     )			->	str:
   __lowerCAmelCase  :			Any					    =						False
   if "IPython" in sys.modules:
      __lowerCAmelCase  :			Optional[int]					    =						"""google.colab""" in str(sys.modules["""IPython"""].get_ipython()     )

   if in_colab:
      if upgrade:
         __lowerCAmelCase  :			int					    =						["""pip""", """install""", """-U""", """torch"""]
         subprocess.run(__A					,   check=__A     )
      # get the current version of torch
      __lowerCAmelCase  :			List[Any]					    =						importlib.metadata.version("""torch"""     )
      __lowerCAmelCase  :			List[Any]					    =						torch_version[: torch_version.rindex("""."""     )]
      __lowerCAmelCase  :			int					    =						f'''https://storage.googleapis.com/tpu-pytorch/wheels/colab/torch_xla-{torch_version_trunc}-cp37-cp37m-linux_x86_64.whl'''
      __lowerCAmelCase  :			List[Any]					    =						["""pip""", """install""", xla_wheel]
      subprocess.run(__A					,   check=__A     )
   else:
      raise RuntimeError("""`install_xla` utility works only on google colab."""     )


