'''simple docstring'''




from __future__ import annotations





def      _UpperCAmelCase    (							_UpperCamelCase    :	Optional[Any]   )	->      Union[str, Any]:
    global graph, reversed_graph, scc, component, visit, stack
    if visit[u]:
        return
    A_     =   True
    for v in graph[u]:
        dfs(_UpperCamelCase   )
    stack.append(_UpperCamelCase   )





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





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


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

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

  __snake_case   :      list[int]						    =  []
  __snake_case   :      list[bool]						    =  [False] * n
  __snake_case   :      list[int]						    =  []
  __snake_case   :      list[int]						    =  []
  print(kosaraju())







'''simple docstring'''




from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_sentencepiece_available, is_tokenizers_available


__snake_case   :      Optional[int]						    =  {}

try:
  if not is_sentencepiece_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __snake_case   :      Optional[Any]						    =  ['MBart50Tokenizer']

try:
  if not is_tokenizers_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __snake_case   :      Dict						    =  ['MBart50TokenizerFast']


if TYPE_CHECKING:
  try:
    if not is_sentencepiece_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .tokenization_mbartaa import MBartaaTokenizer

  try:
    if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .tokenization_mbartaa_fast import MBartaaTokenizerFast

else:
  import sys

  __snake_case   :      Tuple						    =  _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)






