






import math
from collections import OrderedDict

import torch
from packaging import version
from torch import Tensor, nn

from .utils import logging


lowerCamelCase										=  logging.get_logger(__name__)

class 					snake_case_							(       nn.Module      ):







   """simple docstring"""



   def __init__(    self:	Union[str, Any]	)  ->		List[str]:


       """simple docstring"""



       super().__init__()
       if version.parse(torch.__version__	) < version.parse('1.12.0'	):
           raise ImportError(
               f'''You are using torch=={torch.__version__}, but torch>=1.12.0 is required to use '''
               'PytorchGELUTanh. Please upgrade torch.'	)

   def 			SCREAMING_SNAKE_CASE__				(    self:	int   ,       snake_case__:	Optional[int]	)  ->		Dict:


       """simple docstring"""



       return nn.functional.gelu(_lowerCamelCase   ,       approximate='tanh'	)






class 					snake_case_							(       nn.Module      ):







   """simple docstring"""



   def 			SCREAMING_SNAKE_CASE__				(    self:	Optional[int]   ,       snake_case__:	Union[str, Any]	)  ->		Any:


       """simple docstring"""



       return 0.5 * input * (1.0 + torch.tanh(math.sqrt(2.0 / math.pi	) * (input + 0.04_47_15 * torch.pow(_lowerCamelCase   ,       3.0	))	))






class 					snake_case_							(       nn.Module      ):







   """simple docstring"""



   def __init__(    self:	Tuple   ,       snake_case__:	Any = False	)  ->		Optional[Any]:


       """simple docstring"""



       super().__init__()
       if use_gelu_python:
           _lowercase     =	self._gelu_python
       else:
           _lowercase     =	nn.functional.gelu

   def 			SCREAMING_SNAKE_CASE__				(    self:	List[Any]   ,       snake_case__:	Optional[Any]	)  ->		Optional[int]:


       """simple docstring"""



       return input * 0.5 * (1.0 + torch.erf(input / math.sqrt(2.0	)	))

   def 			SCREAMING_SNAKE_CASE__				(    self:	Optional[Any]   ,       snake_case__:	Any	)  ->		int:


       """simple docstring"""



       return self.act(_lowerCamelCase	)






class 					snake_case_							(       nn.Module      ):







   """simple docstring"""



   def 			SCREAMING_SNAKE_CASE__				(    self:	Tuple   ,       snake_case__:	Any	)  ->		List[str]:


       """simple docstring"""



       return 0.5 * input * (1.0 + torch.tanh(input * 0.79_78_84_56_08 * (1.0 + 0.04_47_15 * input * input)	))






class 					snake_case_							(       nn.Module      ):







   """simple docstring"""



   def 			SCREAMING_SNAKE_CASE__				(    self:	int   ,       snake_case__:	Tuple	)  ->		Tuple:


       """simple docstring"""



       return input * torch.sigmoid(1.7_02 * input	)






class 					snake_case_							(       nn.Module      ):







   """simple docstring"""



   def __init__(    self:	int   ,       snake_case__:	Optional[int]   ,       snake_case__:	Union[str, Any]	)  ->		Any:


       """simple docstring"""



       if min > max:
           raise ValueError(f'''min should be < max (got min: {min}, max: {max})'''	)

       super().__init__()
       _lowercase     =	min
       _lowercase     =	max

   def 			SCREAMING_SNAKE_CASE__				(    self:	int   ,       snake_case__:	List[str]	)  ->		str:


       """simple docstring"""



       return torch.clip(gelu(_lowerCamelCase	)   ,       self.min   ,       self.max	)






class 					snake_case_							(       nn.Module      ):







   """simple docstring"""



   def __init__(    self:	List[str]	)  ->		Dict:


       """simple docstring"""



       super().__init__()
       _lowercase     =	math.sqrt(2 / math.pi	)

   def 			SCREAMING_SNAKE_CASE__				(    self:	Tuple   ,       snake_case__:	Optional[int]	)  ->		Optional[int]:


       """simple docstring"""



       return 0.5 * input * (1 + torch.tanh(self.precomputed_constant * (input + 0.04_47_15 * torch.pow(_lowerCamelCase   ,       3	))	))






class 					snake_case_							(       nn.Module      ):







   """simple docstring"""



   def 			SCREAMING_SNAKE_CASE__				(    self:	Optional[Any]   ,       snake_case__:	Dict	)  ->		Optional[int]:


       """simple docstring"""



       return nn.functional.silu(_lowerCamelCase	)






class 					snake_case_							(       nn.Module      ):







   """simple docstring"""



   def __init__(    self:	List[str]	)  ->		Union[str, Any]:


       """simple docstring"""



       super().__init__()
       if version.parse(torch.__version__	) < version.parse('1.9.0'	):
           _lowercase     =	self._mish_python
       else:
           _lowercase     =	nn.functional.mish

   def 			SCREAMING_SNAKE_CASE__				(    self:	Tuple   ,       snake_case__:	Any	)  ->		Optional[int]:


       """simple docstring"""



       return input * torch.tanh(nn.functional.softplus(_lowerCamelCase	)	)

   def 			SCREAMING_SNAKE_CASE__				(    self:	Optional[Any]   ,       snake_case__:	List[str]	)  ->		Union[str, Any]:


       """simple docstring"""



       return self.act(_lowerCamelCase	)






class 					snake_case_							(       nn.Module      ):







   """simple docstring"""



   def 			SCREAMING_SNAKE_CASE__				(    self:	Any   ,       snake_case__:	Dict	)  ->		Dict:


       """simple docstring"""



       return input






class 					snake_case_							(       nn.Module      ):







   """simple docstring"""



   def 			SCREAMING_SNAKE_CASE__				(    self:	Any   ,       snake_case__:	Union[str, Any]   ,       snake_case__:	int=0.70_71_07   ,       snake_case__:	List[str]=0.28_20_95	)  ->		str:


       """simple docstring"""



       _lowercase     =	(input - mu).div(sigma * math.sqrt(2.0	)	)
       return 0.5 * (1.0 + torch.erf(_lowerCamelCase	))






class 					snake_case_							(       nn.Module      ):







   """simple docstring"""



   def 			SCREAMING_SNAKE_CASE__				(    self:	Dict   ,       snake_case__:	Tuple	)  ->		Optional[int]:


       """simple docstring"""



       _lowercase     =	nn.functional.relu(_lowerCamelCase	)
       _lowercase     =	torch.square(_lowerCamelCase	)
       return squared






class 					snake_case_							(       lowerCAmelCase__      ):







   """simple docstring"""



   def __getitem__(    self:	int   ,       snake_case__:	Dict	)  ->		Any:


       """simple docstring"""



       _lowercase     =	super().__getitem__(_lowerCamelCase	)
       _lowercase     =	content if isinstance(_lowerCamelCase   ,       _lowerCamelCase	) else (content, {})
       return cls(**_lowerCamelCase	)






lowerCamelCase										=  {
    '''gelu''': GELUActivation,
    '''gelu_10''': (ClippedGELUActivation, {'''min''': -10, '''max''': 10}),
    '''gelu_fast''': FastGELUActivation,
    '''gelu_new''': NewGELUActivation,
    '''gelu_python''': (GELUActivation, {'''use_gelu_python''': True}),
    '''gelu_pytorch_tanh''': PytorchGELUTanh,
    '''gelu_accurate''': AccurateGELUActivation,
    '''laplace''': LaplaceActivation,
    '''linear''': LinearActivation,
    '''mish''': MishActivation,
    '''quick_gelu''': QuickGELUActivation,
    '''relu''': nn.ReLU,
    '''relu2''': ReLUSquaredActivation,
    '''relu6''': nn.ReLUa,
    '''sigmoid''': nn.Sigmoid,
    '''silu''': SiLUActivation,
    '''swish''': SiLUActivation,
    '''tanh''': nn.Tanh,
}
lowerCamelCase										=  ClassInstantier(ACTaCLS)
def        UpperCAmelCase      (   _lowercase      ):


    '''simple docstring'''



    if activation_string in ACTaFN:
        return ACTaFN[activation_string]
    else:
        raise KeyError(f'''function {activation_string} not found in ACT2FN mapping {list(ACTaFN.keys()      )}'''      )


# For backwards compatibility with: from activations import gelu_python
lowerCamelCase										=  get_activation('''gelu_python''')
lowerCamelCase										=  get_activation('''gelu_new''')
lowerCamelCase										=  get_activation('''gelu''')
lowerCamelCase										=  get_activation('''gelu_fast''')
lowerCamelCase										=  get_activation('''quick_gelu''')
lowerCamelCase										=  get_activation('''silu''')
lowerCamelCase										=  get_activation('''mish''')
lowerCamelCase										=  get_activation('''linear''')








from __future__ import annotations
def        UpperCAmelCase      (   _lowercase      ):


    '''simple docstring'''



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


    '''simple docstring'''



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


    '''simple docstring'''



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