





from __future__ import annotations







def       lowerCAmelCase__(	lowercase       :    List[str]				) ->    Tuple:
  global graph, reversed_graph, scc, component, visit, stack
  if visit[u]:
    return
  __snake_case   :				List[str]        =       True
  for v in graph[u]:
    dfs(lowercase				)
  stack.append(lowercase				)







def       lowerCAmelCase__(	lowercase       :    List[str]				) ->    int:
  global graph, reversed_graph, scc, component, visit, stack
  if visit[u]:
    return
  __snake_case   :				Union[str, Any]        =       True
  component.append(lowercase				)
  for v in reversed_graph[u]:
    dfsa(lowercase				)







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








import torch
from torch import autograd




class 				_lowerCamelCase (    autograd.Function    ):



      """simple docstring"""






      @staticmethod
      def 						UpperCAmelCase		( UpperCAmelCase				,						UpperCAmelCase				,						UpperCAmelCase				,						UpperCAmelCase   )       ->   str:






        '''simple docstring'''






        __snake_case   :				Dict        =       inputs.numel()
        __snake_case   :				Optional[int]        =       int(0.005 * nb_elems   ) + 1
        if sigmoid:
          __snake_case   :				Any        =       (torch.sigmoid(UpperCAmelCase   ) > threshold).type(inputs.type()   )
        else:
          __snake_case   :				Optional[int]        =       (inputs > threshold).type(inputs.type()   )
        if mask.sum() < nb_min:
          # We limit the pruning so that at least 0.5% (half a percent) of the weights are remaining
          __snake_case   :				List[str]        =       inputs.flatten().kthvalue(max(nb_elems - nb_min				,						1   )   ).values
          __snake_case   :				Union[str, Any]        =       (inputs > k_threshold).type(inputs.type()   )
        return mask







      @staticmethod
      def 						UpperCAmelCase		( UpperCAmelCase				,						UpperCAmelCase   )       ->   Optional[int]:






        '''simple docstring'''






        return gradOutput, None, None




class 				_lowerCamelCase (    autograd.Function    ):



      """simple docstring"""






      @staticmethod
      def 						UpperCAmelCase		( UpperCAmelCase				,						UpperCAmelCase				,						UpperCAmelCase   )       ->   Optional[int]:






        '''simple docstring'''






        __snake_case   :				Optional[int]        =       inputs.clone()
        __snake_case    ,   __snake_case   :				int        =       inputs.flatten().sort(descending=UpperCAmelCase   )
        __snake_case   :				Tuple        =       int(threshold * inputs.numel()   )

        # flat_out and mask access the same memory.
        __snake_case   :				Optional[int]        =       mask.flatten()
        __snake_case   :				Union[str, Any]        =       0
        __snake_case   :				Any        =       1
        return mask







      @staticmethod
      def 						UpperCAmelCase		( UpperCAmelCase				,						UpperCAmelCase   )       ->   List[str]:






        '''simple docstring'''






        return gradOutput, None




class 				_lowerCamelCase (    a    ):



      """simple docstring"""






      @staticmethod
      def 						UpperCAmelCase		( UpperCAmelCase				,						UpperCAmelCase   )       ->   Any:






        '''simple docstring'''






        __snake_case   :				Union[str, Any]        =       inputs.clone()
        __snake_case    ,   __snake_case   :				Optional[Any]        =       inputs.abs().flatten().sort(descending=UpperCAmelCase   )
        __snake_case   :				List[Any]        =       int(threshold * inputs.numel()   )

        # flat_out and mask access the same memory.
        __snake_case   :				Optional[Any]        =       mask.flatten()
        __snake_case   :				Tuple        =       0
        __snake_case   :				Any        =       1
        return mask

