
"""simple docstring"""

from typing import TYPE_CHECKING

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


SCREAMING_SNAKE_CASE_			    =  {
    '''configuration_deformable_detr''': ['''DEFORMABLE_DETR_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''DeformableDetrConfig'''],
}

try:
   if not is_vision_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   SCREAMING_SNAKE_CASE_			    =  ['''DeformableDetrFeatureExtractor''']
   SCREAMING_SNAKE_CASE_			    =  ['''DeformableDetrImageProcessor''']

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   SCREAMING_SNAKE_CASE_			    =  [
       '''DEFORMABLE_DETR_PRETRAINED_MODEL_ARCHIVE_LIST''',
       '''DeformableDetrForObjectDetection''',
       '''DeformableDetrModel''',
       '''DeformableDetrPreTrainedModel''',
   ]


if TYPE_CHECKING:
   from .configuration_deformable_detr import DEFORMABLE_DETR_PRETRAINED_CONFIG_ARCHIVE_MAP, DeformableDetrConfig

   try:
      if not is_vision_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .feature_extraction_deformable_detr import DeformableDetrFeatureExtractor
      from .image_processing_deformable_detr import DeformableDetrImageProcessor

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_deformable_detr import (
          DEFORMABLE_DETR_PRETRAINED_MODEL_ARCHIVE_LIST,
          DeformableDetrForObjectDetection,
          DeformableDetrModel,
          DeformableDetrPreTrainedModel,
      )

else:
   import sys

   SCREAMING_SNAKE_CASE_			    =  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)





"""simple docstring"""

from __future__ import annotations




def 			lowercase__  (    lowerCAmelCase :    Dict       )       ->					Optional[int]:






    """simple docstring"""




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




def 			lowercase__  (    lowerCAmelCase :    Optional[int]       )       ->					int:






    """simple docstring"""




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




def 			lowercase__  (    )       ->					List[str]:






    """simple docstring"""




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


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

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

   SCREAMING_SNAKE_CASE_			    =  []
   SCREAMING_SNAKE_CASE_			    =  [False] * n
   SCREAMING_SNAKE_CASE_			    =  []
   SCREAMING_SNAKE_CASE_			    =  []
   print(kosaraju())



