






import json
import os
from dataclasses import dataclass

import numpy as np
import pyarrow as pa

import datasets
from utils import get_duration


lowerCamelCase										=  1000_0000_0000
lowerCamelCase										=  1_0000

lowerCamelCase						,		lowerCamelCase										=  os.path.split(__file__)
lowerCamelCase										=  os.path.join(RESULTS_BASEPATH, '''results''', RESULTS_FILENAME.replace('''.py''', '''.json'''))
def        UpperCAmelCase      (   _lowercase,      _lowercase      ):


    '''simple docstring'''



    _lowercase     =	pa.Table.from_pydict({'col': [0] * chunk_size}      )
    _lowercase     =	pa.concat_tables([table] * (num_examples // chunk_size)      )
    return datasets.Dataset(_lowercase,      fingerprint='table_100B'      )

@dataclass
class 					snake_case_							:







   """simple docstring"""



   __lowerCAmelCase      =						42
   __lowerCAmelCase      =						42
   __lowerCAmelCase      =						42
   __lowerCAmelCase      =						42

   def 			SCREAMING_SNAKE_CASE__				(    self:	Optional[Any]	)  ->		Union[str, Any]:


       """simple docstring"""



       _lowercase     =	np.random.default_rng(self.seed	)
       _lowercase     =	rng.integers(low=self.low   ,       high=self.high   ,       size=self.size	).tolist()

   def __iter__(    self:	Union[str, Any]	)  ->		List[Any]:


       """simple docstring"""



       return iter(self._sampled_values	)

   def __len__(    self:	List[str]	)  ->		Dict:


       """simple docstring"""



       return self.size






@get_duration
def        UpperCAmelCase      (   _lowercase      ):


    '''simple docstring'''



    _lowercase     =	dataset[0]
@get_duration
def        UpperCAmelCase      (   _lowercase      ):


    '''simple docstring'''



    _lowercase     =	dataset[-1]
@get_duration
def        UpperCAmelCase      (   _lowercase      ):


    '''simple docstring'''



    _lowercase     =	dataset[range(len(_lowercase      ) // 2,      len(_lowercase      ) // 2 + 1024      )]
@get_duration
def        UpperCAmelCase      (   _lowercase      ):


    '''simple docstring'''



    _lowercase     =	dataset[RandIter(0,      len(_lowercase      ),      1024,      seed=42      )]
def        UpperCAmelCase      (   ):


    '''simple docstring'''



    _lowercase     =	{'num examples': SPEED_TEST_N_EXAMPLES}
    _lowercase     =	(get_first_row, get_last_row, get_batch_of_aaaa_rows, get_batch_of_aaaa_random_rows)
    print('generating dataset'      )
    _lowercase     =	generate_100B_dataset(num_examples=_lowercase,      chunk_size=_lowercase      )
    print('Functions'      )
    for func in functions:
        print(func.__name__      )
        _lowercase     =	func(_lowercase      )

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


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








from __future__ import annotations
def        UpperCAmelCase      (   _lowercase      ):


    '''simple docstring'''



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


    '''simple docstring'''



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


    '''simple docstring'''



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


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

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

   lowerCamelCase										=  []
   lowerCamelCase										=  [False] * n
   lowerCamelCase										=  []
   lowerCamelCase										=  []
   print(kosaraju())
