
'''simple docstring'''





import os
import unittest

import pytest
from parameterized import parameterized

from transformers.testing_utils import require_torch, require_torch_gpu, slow, torch_device


# skipping in unittest tests

a__						:				Optional[int]           =    [(1,)]





def     snake_case							(						)->     Optional[int]:







      """simple docstring"""
      __A    		=     bool(os.getenv('RUN_SLOW' ,					0		)		)
      if run_slow:
            assert True
      else:
            assert False, "should have been skipped"





def     snake_case							(						)->     Optional[Any]:







      """simple docstring"""
      __A    		=     bool(os.getenv('RUN_SLOW' ,					0		)		)
      if run_slow and torch_device == "cuda":
            assert True
      else:
            assert False, "should have been skipped"


@require_torch
class 	UpperCamelCase__					(      unittest.TestCase):






 @slow
 @require_torch_gpu
 def 		lowercase_  (     self					:Tuple     )			->     Union[str, Any]:







       '''simple docstring'''



       check_slow_torch_cuda()






 @require_torch_gpu
 @slow
 def 		lowercase_  (     self					:Any     )			->     List[str]:







       '''simple docstring'''



       check_slow_torch_cuda()






 @parameterized.expand(_A     )
 @slow
 def 		lowercase_  (     self					:Tuple		,			_A					:Optional[int]=None     )			->     List[Any]:







       '''simple docstring'''



       check_slow()





@slow
@require_torch_gpu
def     snake_case							(						)->     Union[str, Any]:







      """simple docstring"""
      check_slow_torch_cuda()





@require_torch_gpu
@slow
def     snake_case							(						)->     Any:







      """simple docstring"""
      check_slow_torch_cuda()





@slow
@pytest.mark.parametrize('param' ,					[1]		)
def     snake_case							(						UpperCAmelCase		)->     str:







      """simple docstring"""
      check_slow()





@pytest.mark.parametrize('param' ,					[1]		)
@slow
def     snake_case							(						UpperCAmelCase		)->     Union[str, Any]:







      """simple docstring"""
      check_slow()








'''simple docstring'''





from __future__ import annotations





def     snake_case							(						UpperCAmelCase		)->     List[Any]:







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





def     snake_case							(						UpperCAmelCase		)->     List[Any]:







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





def     snake_case							(						)->     Any:







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


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

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

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






