
from __future__ import annotations


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


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


def  A__ (       ):
   global graph, reversed_graph, scc, component, visit, stack
   for i in range(__lowerCamelCase						):
      dfs(__lowerCamelCase						)
   SCREAMING_SNAKE_CASE_	=      [False] * n
   for i in stack[::-1]:
      if visit[i]:
         continue
      SCREAMING_SNAKE_CASE_	=      []
      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())




from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


__UpperCAmelCase   						=     {
    "configuration_donut_swin": ["DONUT_SWIN_PRETRAINED_CONFIG_ARCHIVE_MAP", "DonutSwinConfig"],
    "processing_donut": ["DonutProcessor"],
}

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   __UpperCAmelCase   						=     [
       "DONUT_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST",
       "DonutSwinModel",
       "DonutSwinPreTrainedModel",
   ]

try:
   if not is_vision_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   __UpperCAmelCase   						=     ["DonutFeatureExtractor"]
   __UpperCAmelCase   						=     ["DonutImageProcessor"]


if TYPE_CHECKING:
   from .configuration_donut_swin import DONUT_SWIN_PRETRAINED_CONFIG_ARCHIVE_MAP, DonutSwinConfig
   from .processing_donut import DonutProcessor

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_donut_swin import (
          DONUT_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST,
          DonutSwinModel,
          DonutSwinPreTrainedModel,
      )

   try:
      if not is_vision_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .feature_extraction_donut import DonutFeatureExtractor
      from .image_processing_donut import DonutImageProcessor

else:
   import sys

   __UpperCAmelCase   						=     _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)


