import json
import os
import tempfile

import datasets
from utils import generate_example_dataset, get_duration


_SCREAMING_SNAKE_CASE   		=			5_0_0_0_0_0

_SCREAMING_SNAKE_CASE		,  _SCREAMING_SNAKE_CASE   		=			os.path.split(__file__)
_SCREAMING_SNAKE_CASE   		=			os.path.join(RESULTS_BASEPATH, """results""", RESULTS_FILENAME.replace(""".py""", """.json"""))





@get_duration
def  lowercase(  UpperCamelCase_					)		->  Optional[int]:







 '''simple docstring'''
 UpperCamelCase      =			dataset.select(range(0       ,				len(UpperCamelCase_					)       ,				2					)					)





@get_duration
def  lowercase(  UpperCamelCase_					)		->  List[str]:







 '''simple docstring'''
 UpperCamelCase      =			dataset.sort("""numbers"""					)





@get_duration
def  lowercase(  UpperCamelCase_					)		->  List[Any]:







 '''simple docstring'''
 UpperCamelCase      =			dataset.shuffle()





@get_duration
def  lowercase(  UpperCamelCase_					)		->  Optional[Any]:







 '''simple docstring'''
 UpperCamelCase      =			dataset.train_test_split(0.1					)





@get_duration
def  lowercase(  UpperCamelCase_       ,				UpperCamelCase_=10					)		->  int:







 '''simple docstring'''
 for shard_id in range(UpperCamelCase_					):
  UpperCamelCase      =			dataset.shard(UpperCamelCase_       ,				UpperCamelCase_					)





def  lowercase(  )		->  Optional[Any]:







 '''simple docstring'''
 UpperCamelCase      =			{"""num examples""": SPEED_TEST_N_EXAMPLES}
 UpperCamelCase      =			(select, sort, shuffle, train_test_split, shard)
 with tempfile.TemporaryDirectory() as tmp_dir:
  print("""generating dataset"""					)
  UpperCamelCase      =			datasets.Features({"""text""": datasets.Value("""string"""					), """numbers""": datasets.Value("""float32"""					)}					)
  UpperCamelCase      =			generate_example_dataset(
      os.path.join(UpperCamelCase_       ,				"""dataset.arrow"""					)       ,				UpperCamelCase_       ,				num_examples=UpperCamelCase_					)
  print("""Functions"""					)
  for func in functions:
   print(func.__name__					)
   UpperCamelCase      =			func(UpperCamelCase_					)

 with open(UpperCamelCase_       ,				"""wb"""					) as f:
  f.write(json.dumps(UpperCamelCase_					).encode("""utf-8"""					)					)


if __name__ == "__main__":  # useful to run the profiler
     benchmark_indices_mapping()

from __future__ import annotations





def  lowercase(  UpperCamelCase_					)		->  Dict:







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





def  lowercase(  UpperCamelCase_					)		->  Optional[int]:







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





def  lowercase(  )		->  Any:







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