'''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

_lowercase		:					int													=		[(1,)]




def 				lowerCamelCase      ( )     -> Dict:
							lowercase_   :     Union[str, Any]									=			bool(os.getenv("""RUN_SLOW""" , 0					)					)
							if run_slow:
														assert True
							else:
														assert False, "should have been skipped"




def 				lowerCamelCase      ( )     -> List[str]:
							lowercase_   :     Union[str, Any]									=			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        __magic_name__		(       unittest.TestCase):







			@slow
			@require_torch_gpu
			def       SCREAMING_SNAKE_CASE_	(      self							:    Dict       ):
										check_slow_torch_cuda()







			@require_torch_gpu
			@slow
			def       SCREAMING_SNAKE_CASE_	(      self							:    List[str]       ):
										check_slow_torch_cuda()







			@parameterized.expand(lowercase_       )
			@slow
			def       SCREAMING_SNAKE_CASE_	(      self							:    Tuple							,     lowercase_							:    Dict=None       ):
										check_slow()




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




@require_torch_gpu
@slow
def 				lowerCamelCase      ( )     -> Any:
							check_slow_torch_cuda()




@slow
@pytest.mark.parametrize("""param""" , [1]					)
def 				lowerCamelCase      ( UpperCAmelCase__			:   List[str]					)     -> List[Any]:
							check_slow()




@pytest.mark.parametrize("""param""" , [1]					)
@slow
def 				lowerCamelCase      ( UpperCAmelCase__			:   Optional[Any]					)     -> Any:
							check_slow()






'''simple docstring'''




from __future__ import annotations




def 				lowerCamelCase      ( UpperCAmelCase__			:   str					)     -> Any:
							global graph, reversed_graph, scc, component, visit, stack
							if visit[u]:
														return
							lowercase_   :     int									=			True
							for v in graph[u]:
														dfs(UpperCAmelCase__					)
							stack.append(UpperCAmelCase__					)




def 				lowerCamelCase      ( UpperCAmelCase__			:   int					)     -> str:
							global graph, reversed_graph, scc, component, visit, stack
							if visit[u]:
														return
							lowercase_   :     Tuple									=			True
							component.append(UpperCAmelCase__					)
							for v in reversed_graph[u]:
														dfsa(UpperCAmelCase__					)




def 				lowerCamelCase      ( )     -> int:
							global graph, reversed_graph, scc, component, visit, stack
							for i in range(UpperCAmelCase__					):
														dfs(UpperCAmelCase__					)
							lowercase_   :     Optional[int]									=			[False] * n
							for i in stack[::-1]:
														if visit[i]:
																					continue
														lowercase_   :     Union[str, Any]									=			[]
														dfsa(UpperCAmelCase__					)
														scc.append(UpperCAmelCase__					)
							return scc


if __name__ == "__main__":
						# n - no of nodes, m - no of edges
						_lowercase							,			_lowercase		:					Optional[Any]													=		list(map(int, input().strip().split()))

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

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





