"""simple docstring"""







from __future__ import annotations



def       A__    (	lowercase_     :	Dict						)  ->							List[str]:
   global graph, reversed_graph, scc, component, visit, stack
   if visit[u]:
      return
   __lowerCamelCase    		=					True
   for v in graph[u]:
      dfs(lowercase_						)
   stack.append(lowercase_						)



def       A__    (	lowercase_     :	Union[str, Any]						)  ->							List[str]:
   global graph, reversed_graph, scc, component, visit, stack
   if visit[u]:
      return
   __lowerCamelCase    		=					True
   component.append(lowercase_						)
   for v in reversed_graph[u]:
      dfsa(lowercase_						)



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


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

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

     _SCREAMING_SNAKE_CASE	:		Optional[int]   =   []
     _SCREAMING_SNAKE_CASE	:		Tuple   =   [False] * n
     _SCREAMING_SNAKE_CASE	:		Any   =   []
     _SCREAMING_SNAKE_CASE	:		List[Any]   =   []
     print(kosaraju())












class 			_lowerCamelCase    :

      """simple docstring"""

      def __init__(  self       :			Optional[Any]			,							snake_case       :			int					):
          __UpperCamelCase			=    data
          __UpperCamelCase			=    42
          __UpperCamelCase			=    42







def        __SCREAMING_SNAKE_CASE (	lowercase_   )							->						None:

    """simple docstring"""


    __UpperCamelCase			=    0
    __UpperCamelCase			=    x




def        __SCREAMING_SNAKE_CASE (	lowercase_       ,  lowercase_   )							->						None:

    """simple docstring"""


    __UpperCamelCase		,   __UpperCamelCase			=    find_set(lowercase_   ), find_set(lowercase_   )
    if x == y:
        return

    elif x.rank > y.rank:
        __UpperCamelCase			=    x
    else:
        __UpperCamelCase			=    y
        if x.rank == y.rank:
            y.rank += 1




def        __SCREAMING_SNAKE_CASE (	lowercase_   )							->						Node:

    """simple docstring"""


    if x != x.parent:
        __UpperCamelCase			=    find_set(x.parent   )
    return x.parent




def        __SCREAMING_SNAKE_CASE (	lowercase_   )							->						set:

    """simple docstring"""


    __UpperCamelCase			=    ({0, 1, 2}, {3, 4, 5})
    for s in sets:
        if node.data in s:
            return s
    __UpperCamelCase			=    F"{node.data} is not in {sets}"
    raise ValueError(lowercase_   )




def        __SCREAMING_SNAKE_CASE (	)							->						None:

    """simple docstring"""


    __UpperCamelCase			=    [Node(lowercase_   ) for i in range(6   )]
    for v in vertex:
        make_set(lowercase_   )

    union_set(vertex[0]       ,  vertex[1]   )
    union_set(vertex[1]       ,  vertex[2]   )
    union_set(vertex[3]       ,  vertex[4]   )
    union_set(vertex[3]       ,  vertex[5]   )

    for nodea in vertex:
        for nodea in vertex:
            if find_python_set(lowercase_   ).isdisjoint(find_python_set(lowercase_   )   ):
                assert find_set(lowercase_   ) != find_set(lowercase_   )
            else:
                assert find_set(lowercase_   ) == find_set(lowercase_   )


if __name__ == "__main__":
 test_disjoint_set()






