

import sys
from collections.abc import Mapping

import numpy as np
import pyarrow as pa

from .. import config
from ..utils.py_utils import map_nested
from .formatting import TensorFormatter






class 	__magic_name__				(       TensorFormatter[Mapping, np.ndarray, Mapping]							):






     def __init__(							self		,	_lowercase=None		,	**_lowercase  )->    List[Any]:
         super().__init__(features=_lowercase  )
         UpperCamelCase_      =	np_array_kwargs






     def   UpperCAmelCase_							(							self		,	_lowercase  )->    int:
         if isinstance(_lowercase		,	_lowercase  ):
             if column and all(
                 isinstance(_lowercase		,	np.ndarray  ) and x.shape == column[0].shape and x.dtype == column[0].dtype for x in column  ):
                 return np.stack(_lowercase  )
             else:
                 # don't use np.array(column, dtype=object)
                 # since it fails in certain cases
                 # see https://stackoverflow.com/q/51005699
                 UpperCamelCase_      =	np.empty(len(_lowercase  )		,	dtype=_lowercase  )
                 UpperCamelCase_      =	column
                 return out
         return column






     def   UpperCAmelCase_							(							self		,	_lowercase  )->    List[str]:
         if isinstance(_lowercase		,	(str, bytes, type(_lowercase  ))  ):
             return value
         elif isinstance(_lowercase		,	(np.character, np.ndarray)  ) and np.issubdtype(value.dtype		,	np.character  ):
             return value
         elif isinstance(_lowercase		,	np.number  ):
             return value

         UpperCamelCase_      =	{}

         if isinstance(_lowercase		,	np.ndarray  ) and np.issubdtype(value.dtype		,	np.integer  ):
             UpperCamelCase_      =	{"dtype": np.intaa}
         elif isinstance(_lowercase		,	np.ndarray  ) and np.issubdtype(value.dtype		,	np.floating  ):
             UpperCamelCase_      =	{"dtype": np.floataa}
         elif config.PIL_AVAILABLE and "PIL" in sys.modules:
             import PIL.Image

             if isinstance(_lowercase		,	PIL.Image.Image  ):
                 return np.asarray(_lowercase		,	**self.np_array_kwargs  )

         return np.asarray(_lowercase		,	**{**default_dtype, **self.np_array_kwargs}  )






     def   UpperCAmelCase_							(							self		,	_lowercase  )->    Tuple:
         # support for torch, tf, jax etc.
         if config.TORCH_AVAILABLE and "torch" in sys.modules:
             import torch

             if isinstance(_lowercase		,	torch.Tensor  ):
                 return self._tensorize(data_struct.detach().cpu().numpy()[()]  )
         if hasattr(_lowercase		,	"__array__"  ) and not isinstance(_lowercase		,	(np.ndarray, np.character, np.number)  ):
             UpperCamelCase_      =	data_struct.__array__()
         # support for nested types like struct of list of struct
         if isinstance(_lowercase		,	np.ndarray  ):
             if data_struct.dtype == object:
                 return self._consolidate([self.recursive_tensorize(_lowercase  ) for substruct in data_struct]  )
         if isinstance(_lowercase		,	(list, tuple)  ):
             return self._consolidate([self.recursive_tensorize(_lowercase  ) for substruct in data_struct]  )
         return self._tensorize(_lowercase  )






     def   UpperCAmelCase_							(							self		,	_lowercase  )->    Optional[Any]:
         return map_nested(self._recursive_tensorize		,	_lowercase		,	map_list=_lowercase  )






     def   UpperCAmelCase_							(							self		,	_lowercase  )->    Mapping:
         UpperCamelCase_      =	self.numpy_arrow_extractor().extract_row(_lowercase  )
         UpperCamelCase_      =	self.python_features_decoder.decode_row(_lowercase  )
         return self.recursive_tensorize(_lowercase  )






     def   UpperCAmelCase_							(							self		,	_lowercase  )->    np.ndarray:
         UpperCamelCase_      =	self.numpy_arrow_extractor().extract_column(_lowercase  )
         UpperCamelCase_      =	self.python_features_decoder.decode_column(_lowercase		,	pa_table.column_names[0]  )
         UpperCamelCase_      =	self.recursive_tensorize(_lowercase  )
         UpperCamelCase_      =	self._consolidate(_lowercase  )
         return column






     def   UpperCAmelCase_							(							self		,	_lowercase  )->    Mapping:
         UpperCamelCase_      =	self.numpy_arrow_extractor().extract_batch(_lowercase  )
         UpperCamelCase_      =	self.python_features_decoder.decode_batch(_lowercase  )
         UpperCamelCase_      =	self.recursive_tensorize(_lowercase  )
         for column_name in batch:
             UpperCamelCase_      =	self._consolidate(batch[column_name]  )
         return batch



from __future__ import annotations




def  lowerCAmelCase(			SCREAMING_SNAKE_CASE_ )->	str:



    """simple docstring"""






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




def  lowerCAmelCase(			SCREAMING_SNAKE_CASE_ )->	Dict:



    """simple docstring"""






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




def  lowerCAmelCase(			)->	Dict:



    """simple docstring"""






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


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

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

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