






from __future__ import annotations




def       _a   (							lowerCamelCase__				)  ->      List[str]:
 global graph, reversed_graph, scc, component, visit, stack
 if visit[u]:
  return
 lowerCamelCase_							:    Union[str, Any]							=     True
 for v in graph[u]:
  dfs(lowerCamelCase__				)
 stack.append(lowerCamelCase__				)




def       _a   (							lowerCamelCase__				)  ->      List[Any]:
 global graph, reversed_graph, scc, component, visit, stack
 if visit[u]:
  return
 lowerCamelCase_							:    Optional[Any]							=     True
 component.append(lowerCamelCase__				)
 for v in reversed_graph[u]:
  dfsa(lowerCamelCase__				)




def       _a   (							)  ->      Any:
 global graph, reversed_graph, scc, component, visit, stack
 for i in range(lowerCamelCase__				):
  dfs(lowerCamelCase__				)
 lowerCamelCase_							:    int							=     [False] * n
 for i in stack[::-1]:
  if visit[i]:
   continue
  lowerCamelCase_							:    Any							=     []
  dfsa(lowerCamelCase__				)
  scc.append(lowerCamelCase__				)
 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())








def       _a   (							lowerCamelCase__				)  ->      list[int]:
 if len(lowerCamelCase__				) > 1:
  lowerCamelCase_							:    Optional[Any]							=     len(lowerCamelCase__				) // 2  # Finds the middle of the array
  lowerCamelCase_							:    int							=     arr[
      :middle_length
  ]  # Creates an array of the elements in the first half.
  lowerCamelCase_							:    List[Any]							=     arr[
      middle_length:
  ]  # Creates an array of the elements in the second half.
  lowerCamelCase_							:    Optional[Any]							=     len(lowerCamelCase__				)
  lowerCamelCase_							:    Optional[Any]							=     len(lowerCamelCase__				)
  merge(lowerCamelCase__				)  # Starts sorting the left.
  merge(lowerCamelCase__				)  # Starts sorting the right
  lowerCamelCase_							:    Dict							=     0  # Left Counter
  lowerCamelCase_							:    str							=     0  # Right Counter
  lowerCamelCase_							:    Tuple							=     0  # Position Counter
  while (
      left_index < left_size and right_index < right_size
  ):  # Runs until the lowers size of the left and right are sorted.
   if left_array[left_index] < right_array[right_index]:
    lowerCamelCase_							:    Optional[int]							=     left_array[left_index]
    left_index += 1
   else:
    lowerCamelCase_							:    Union[str, Any]							=     right_array[right_index]
    right_index += 1
   index += 1
  while (
      left_index < left_size
  ):  # Adds the left over elements in the left half of the array
   lowerCamelCase_							:    Tuple							=     left_array[left_index]
   left_index += 1
   index += 1
  while (
      right_index < right_size
  ):  # Adds the left over elements in the right half of the array
   lowerCamelCase_							:    Optional[int]							=     right_array[right_index]
   right_index += 1
   index += 1
 return arr


if __name__ == "__main__":
       import doctest

       doctest.testmod()
