import enum
import inspect
from typing import Iterable, List, Optional, Tuple, Union
class        a_				(		enum.Enum		):






 '''simple docstring'''






 UpperCAmelCase_							=      '''timm'''
 UpperCAmelCase_							=      '''transformers'''






def    __lowerCamelCase	(		lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			):
       if stage_names is None:
              raise ValueError('Stage_names must be set for transformers backbones'			)

       if out_features is not None:
              if not isinstance(__lowerCAmelCase			,						(list,)			):
                     raise ValueError(F'''out_features must be a list {type(__lowerCAmelCase			)}'''			)
              if any(feat not in stage_names for feat in out_features			):
                     raise ValueError(F'''out_features must be a subset of stage_names: {stage_names} got {out_features}'''			)

       if out_indices is not None:
              if not isinstance(__lowerCAmelCase			,						(list, tuple)			):
                     raise ValueError(F'''out_indices must be a list or tuple, got {type(__lowerCAmelCase			)}'''			)
              if any(idx >= len(__lowerCAmelCase			) for idx in out_indices			):
                     raise ValueError('out_indices must be valid indices for stage_names {stage_names}, got {out_indices}'			)

       if out_features is not None and out_indices is not None:
              if len(__lowerCAmelCase			) != len(__lowerCAmelCase			):
                     raise ValueError('out_features and out_indices should have the same length if both are set'			)
              if out_features != [stage_names[idx] for idx in out_indices]:
                     raise ValueError('out_features and out_indices should correspond to the same stages if both are set'			)






def    __lowerCamelCase	(		lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						):
       if out_indices is None and out_features is None:
              lowerCAmelCase__  			=      [len(__lowerCAmelCase			) - 1]
              lowerCAmelCase__  			=      [stage_names[-1]]
       elif out_indices is None and out_features is not None:
              lowerCAmelCase__  			=      [stage_names.index(__lowerCAmelCase			) for layer in out_features]
       elif out_features is None and out_indices is not None:
              lowerCAmelCase__  			=      [stage_names[idx] for idx in out_indices]
       return out_features, out_indices






def    __lowerCamelCase	(		lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__			,						):
       verify_out_features_out_indices(out_features=__lowerCAmelCase			,						out_indices=__lowerCAmelCase			,						stage_names=__lowerCAmelCase			)
       lowerCAmelCase__  			=      _align_output_features_output_indices(
           out_features=__lowerCAmelCase			,						out_indices=__lowerCAmelCase			,						stage_names=__lowerCAmelCase			)
       # Verify that the aligned out_features and out_indices are valid
       verify_out_features_out_indices(out_features=__lowerCAmelCase			,						out_indices=__lowerCAmelCase			,						stage_names=__lowerCAmelCase			)
       return output_features, output_indices
class        a_				:






 '''simple docstring'''






 UpperCAmelCase_							=      None




 def 	__snake_case		(    self      :						str    ,					lowercase__      :						Dict):







        '''simple docstring'''



        if getattr(self    ,					'_backbone'    ,					lowercase__) is None:
               raise ValueError('self._backbone must be set before calling _init_timm_backbone')

        # These will diagree with the defaults for the transformers models e.g. for resnet50
        # the transformer model has out_features = ['stem', 'stage1', 'stage2', 'stage3', 'stage4']
        # the timm model has out_features = ['act', 'layer1', 'layer2', 'layer3', 'layer4']
        lowerCAmelCase__  			=      [stage["module"] for stage in self._backbone.feature_info.info]
        lowerCAmelCase__  			=      [stage["num_chs"] for stage in self._backbone.feature_info.info]
        lowerCAmelCase__  			=      self._backbone.feature_info.out_indices
        lowerCAmelCase__  			=      self._backbone.feature_info.module_name()

        # We verify the out indices and out features are valid
        verify_out_features_out_indices(
            out_features=lowercase__    ,					out_indices=lowercase__    ,					stage_names=self.stage_names)
        lowerCAmelCase__  			=      out_features, out_indices




 def 	__snake_case		(    self      :						int    ,					lowercase__      :						Union[str, Any]):







        '''simple docstring'''



        lowerCAmelCase__  			=      getattr(lowercase__    ,					'stage_names')
        lowerCAmelCase__  			=      getattr(lowercase__    ,					'out_features'    ,					lowercase__)
        lowerCAmelCase__  			=      getattr(lowercase__    ,					'out_indices'    ,					lowercase__)

        lowerCAmelCase__  			=      stage_names
        lowerCAmelCase__  			=      get_aligned_output_features_output_indices(
            out_features=lowercase__    ,					out_indices=lowercase__    ,					stage_names=lowercase__)
        # Number of channels for each stage. This is set in the transformer backbone model init
        lowerCAmelCase__  			=      None




 def 	__snake_case		(    self      :						Optional[int]    ,					lowercase__      :						List[str]):







        '''simple docstring'''



        lowerCAmelCase__  			=      config

        lowerCAmelCase__  			=      getattr(lowercase__    ,					'use_timm_backbone'    ,					lowercase__)
        lowerCAmelCase__  			=      BackboneType.TIMM if self.use_timm_backbone else BackboneType.TRANSFORMERS

        if self.backbone_type == BackboneType.TIMM:
               self._init_timm_backbone(lowercase__)
        elif self.backbone_type == BackboneType.TRANSFORMERS:
               self._init_transformers_backbone(lowercase__)
        else:
               raise ValueError(F'''backbone_type {self.backbone_type} not supported.''')




 @property
 def 	__snake_case		(    self      :						List[Any]):







        '''simple docstring'''



        return self._out_features




 @out_features.setter
 def 	__snake_case		(    self      :						Dict    ,					lowercase__      :						List[str]):







        '''simple docstring'''



        lowerCAmelCase__  			=      get_aligned_output_features_output_indices(
            out_features=lowercase__    ,					out_indices=lowercase__    ,					stage_names=self.stage_names)




 @property
 def 	__snake_case		(    self      :						Optional[Any]):







        '''simple docstring'''



        return self._out_indices




 @out_indices.setter
 def 	__snake_case		(    self      :						Optional[int]    ,					lowercase__      :						Union[Tuple[int], List[int]]):







        '''simple docstring'''



        lowerCAmelCase__  			=      get_aligned_output_features_output_indices(
            out_features=lowercase__    ,					out_indices=lowercase__    ,					stage_names=self.stage_names)




 @property
 def 	__snake_case		(    self      :						int):







        '''simple docstring'''



        return {stage: self.num_features[i] for i, stage in enumerate(self.stage_names)}




 @property
 def 	__snake_case		(    self      :						Optional[int]):







        '''simple docstring'''



        return [self.out_feature_channels[name] for name in self.out_features]




 def 	__snake_case		(    self      :						List[str]    ,					*lowercase__      :						List[str]    ,					**lowercase__      :						str):







        '''simple docstring'''



        lowerCAmelCase__  			=      dict(inspect.signature(self.forward).parameters)
        lowerCAmelCase__  			=      {k: v for k, v in kwargs.items() if k in signature}
        return self(*lowercase__    ,					**lowercase__)




 def 	__snake_case		(    self      :						List[str]    ,					lowercase__      :						List[str]    ,					lowercase__      :						Optional[bool] = None    ,					lowercase__      :						Optional[bool] = None    ,					lowercase__      :						Optional[bool] = None    ,					):







        '''simple docstring'''



        raise NotImplementedError('This method should be implemented by the derived class.')




 def 	__snake_case		(    self      :						Tuple):







        '''simple docstring'''



        lowerCAmelCase__  			=      super().to_dict()
        lowerCAmelCase__  			=      output.pop('_out_features')
        lowerCAmelCase__  			=      output.pop('_out_indices')
        return output






class        a_				:






 '''simple docstring'''






 @property
 def 	__snake_case		(    self      :						Union[str, Any]):







        '''simple docstring'''



        return self._out_features




 @out_features.setter
 def 	__snake_case		(    self      :						Any    ,					lowercase__      :						List[str]):







        '''simple docstring'''



        lowerCAmelCase__  			=      get_aligned_output_features_output_indices(
            out_features=lowercase__    ,					out_indices=lowercase__    ,					stage_names=self.stage_names)




 @property
 def 	__snake_case		(    self      :						Optional[int]):







        '''simple docstring'''



        return self._out_indices




 @out_indices.setter
 def 	__snake_case		(    self      :						List[str]    ,					lowercase__      :						Union[Tuple[int], List[int]]):







        '''simple docstring'''



        lowerCAmelCase__  			=      get_aligned_output_features_output_indices(
            out_features=lowercase__    ,					out_indices=lowercase__    ,					stage_names=self.stage_names)




 def 	__snake_case		(    self      :						Union[str, Any]):







        '''simple docstring'''



        lowerCAmelCase__  			=      super().to_dict()
        lowerCAmelCase__  			=      output.pop('_out_features')
        lowerCAmelCase__  			=      output.pop('_out_indices')
        return output

from __future__ import annotations






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






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






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


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

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

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