
"""simple docstring"""

import torch
from torch import autograd
class    _UpperCAmelCase							(						autograd.Function							):




      @staticmethod
      def 			a_					(							lowercase_      ,				lowercase_      ,				lowercase_      ,				lowercase_							)  ->    Dict:
          UpperCAmelCase  	=    inputs.numel()
          UpperCAmelCase  	=    int(0.0_0_5 * nb_elems							) + 1
          if sigmoid:
              UpperCAmelCase  	=    (torch.sigmoid(lowercase_							) > threshold).type(inputs.type()							)
          else:
              UpperCAmelCase  	=    (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
              UpperCAmelCase  	=    inputs.flatten().kthvalue(max(nb_elems - nb_min      ,				1							)							).values
              UpperCAmelCase  	=    (inputs > k_threshold).type(inputs.type()							)
          return mask




      @staticmethod
      def 			a_					(							lowercase_      ,				lowercase_							)  ->    Tuple:
          return gradOutput, None, None

class    _UpperCAmelCase							(						autograd.Function							):




      @staticmethod
      def 			a_					(							lowercase_      ,				lowercase_      ,				lowercase_							)  ->    Optional[Any]:
          UpperCAmelCase  	=    inputs.clone()
          UpperCAmelCase	,							UpperCAmelCase  	=    inputs.flatten().sort(descending=lowercase_							)
          UpperCAmelCase  	=    int(threshold * inputs.numel()							)

          # flat_out and mask access the same memory.
          UpperCAmelCase  	=    mask.flatten()
          UpperCAmelCase  	=    0
          UpperCAmelCase  	=    1
          return mask




      @staticmethod
      def 			a_					(							lowercase_      ,				lowercase_							)  ->    Optional[Any]:
          return gradOutput, None

class    _UpperCAmelCase							(						SCREAMING_SNAKE_CASE_							):




      @staticmethod
      def 			a_					(							lowercase_      ,				lowercase_							)  ->    Optional[int]:
          UpperCAmelCase  	=    inputs.clone()
          UpperCAmelCase	,							UpperCAmelCase  	=    inputs.abs().flatten().sort(descending=lowercase_							)
          UpperCAmelCase  	=    int(threshold * inputs.numel()							)

          # flat_out and mask access the same memory.
          UpperCAmelCase  	=    mask.flatten()
          UpperCAmelCase  	=    0
          UpperCAmelCase  	=    1
          return mask





"""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())



