
'''simple docstring'''





import logging
import os
import sys
import threading
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

from tqdm import auto as tqdm_lib


a__						:				List[Any]           =    threading.Lock()
a__						:				Optional[logging.Handler]           =    None

a__						:				Tuple           =    {
    "debug": logging.DEBUG,
    "info": logging.INFO,
    "warning": logging.WARNING,
    "error": logging.ERROR,
    "critical": logging.CRITICAL,
}

a__						:				List[Any]           =    logging.WARNING

a__						:				int           =    True





def     snake_case							(						)->     str:







      """simple docstring"""
      __A    		=     os.getenv('DIFFUSERS_VERBOSITY' ,					UpperCAmelCase		)
      if env_level_str:
            if env_level_str in log_levels:
                  return log_levels[env_level_str]
            else:
                  logging.getLogger().warning(
                      f'Unknown option DIFFUSERS_VERBOSITY={env_level_str}, '
                      f'has to be one of: { ", ".join(log_levels.keys()		) }'		)
      return _default_log_level





def     snake_case							(						)->     str:







      """simple docstring"""
      return __name__.split('.'		)[0]





def     snake_case							(						)->     logging.Logger:







      """simple docstring"""
      return logging.getLogger(_get_library_name()		)





def     snake_case							(						)->     None:







      """simple docstring"""
      global _default_handler

      with _lock:
            if _default_handler:
                  # This library has already configured the library root logger.
                  return
            __A    		=     logging.StreamHandler()  # Set sys.stderr as stream.
            __A    		=     sys.stderr.flush

            # Apply our default configuration to the library root logger.
            __A    		=     _get_library_root_logger()
            library_root_logger.addHandler(_default_handler		)
            library_root_logger.setLevel(_get_default_logging_level()		)
            __A    		=     False





def     snake_case							(						)->     None:







      """simple docstring"""
      global _default_handler

      with _lock:
            if not _default_handler:
                  return

            __A    		=     _get_library_root_logger()
            library_root_logger.removeHandler(_default_handler		)
            library_root_logger.setLevel(logging.NOTSET		)
            __A    		=     None





def     snake_case							(						)->     Tuple:







      """simple docstring"""
      return log_levels





def     snake_case							(						UpperCAmelCase = None		)->     logging.Logger:







      """simple docstring"""

      if name is None:
            __A    		=     _get_library_name()

      _configure_library_root_logger()
      return logging.getLogger(UpperCAmelCase		)





def     snake_case							(						)->     int:







      """simple docstring"""
      _configure_library_root_logger()
      return _get_library_root_logger().getEffectiveLevel()





def     snake_case							(						UpperCAmelCase		)->     None:







      """simple docstring"""
      _configure_library_root_logger()
      _get_library_root_logger().setLevel(UpperCAmelCase		)





def     snake_case							(						)->     Dict:







      """simple docstring"""
      return set_verbosity(UpperCAmelCase		)





def     snake_case							(						)->     Dict:







      """simple docstring"""
      return set_verbosity(UpperCAmelCase		)





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







      """simple docstring"""
      return set_verbosity(UpperCAmelCase		)





def     snake_case							(						)->     int:







      """simple docstring"""
      return set_verbosity(UpperCAmelCase		)





def     snake_case							(						)->     None:







      """simple docstring"""
      _configure_library_root_logger()

      assert _default_handler is not None
      _get_library_root_logger().removeHandler(_default_handler		)





def     snake_case							(						)->     None:







      """simple docstring"""
      _configure_library_root_logger()

      assert _default_handler is not None
      _get_library_root_logger().addHandler(_default_handler		)





def     snake_case							(						UpperCAmelCase		)->     None:







      """simple docstring"""
      _configure_library_root_logger()

      assert handler is not None
      _get_library_root_logger().addHandler(UpperCAmelCase		)





def     snake_case							(						UpperCAmelCase		)->     None:







      """simple docstring"""
      _configure_library_root_logger()

      assert handler is not None and handler not in _get_library_root_logger().handlers
      _get_library_root_logger().removeHandler(UpperCAmelCase		)





def     snake_case							(						)->     None:







      """simple docstring"""
      _configure_library_root_logger()
      __A    		=     False





def     snake_case							(						)->     None:







      """simple docstring"""
      _configure_library_root_logger()
      __A    		=     True





def     snake_case							(						)->     None:







      """simple docstring"""
      __A    		=     _get_library_root_logger().handlers

      for handler in handlers:
            __A    		=     logging.Formatter('[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s'		)
            handler.setFormatter(UpperCAmelCase		)





def     snake_case							(						)->     None:







      """simple docstring"""
      __A    		=     _get_library_root_logger().handlers

      for handler in handlers:
            handler.setFormatter(UpperCAmelCase		)





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







      """simple docstring"""
      __A    		=     os.getenv('DIFFUSERS_NO_ADVISORY_WARNINGS' ,					UpperCAmelCase		)
      if no_advisory_warnings:
            return
      self.warning(*UpperCAmelCase ,					**UpperCAmelCase		)


a__						:				Union[str, Any]           =    warning_advice


class 	UpperCamelCase__					:






 def __init__(     self					:Optional[Any]		,			*_A					:Tuple		,			**_A					:Optional[int]     )			->     Dict:  # pylint: disable=unused-argument







       '''simple docstring'''



       __A    		=     args[0] if args else None






 def __iter__(     self					:Dict     )			->     Dict:







       '''simple docstring'''



       return iter(self._iterator     )






 def __getattr__(     self					:Dict		,			_A					:Tuple     )			->     Dict:







       '''simple docstring'''



       def empty_fn(*_A					:Optional[int]		,			**_A					:int     ):  # pylint: disable=unused-argument
             return

       return empty_fn






 def __enter__(     self					:str     )			->     Optional[int]:







       '''simple docstring'''



       return self






 def __exit__(     self					:Any		,			_A					:Optional[Any]		,			_A					:int		,			_A					:Any     )			->     Optional[Any]:







       '''simple docstring'''



       return


class 	UpperCamelCase__					:






 def __call__(     self					:Union[str, Any]		,			*_A					:Tuple		,			**_A					:List[Any]     )			->     str:







       '''simple docstring'''



       if _tqdm_active:
             return tqdm_lib.tqdm(*_A		,			**_A     )
       else:
             return EmptyTqdm(*_A		,			**_A     )






 def 		lowercase_  (     self					:List[Any]		,			*_A					:Tuple		,			**_A					:Union[str, Any]     )			->     Optional[Any]:







       '''simple docstring'''



       __A    		=     None
       if _tqdm_active:
             return tqdm_lib.tqdm.set_lock(*_A		,			**_A     )






 def 		lowercase_  (     self					:List[Any]     )			->     Any:







       '''simple docstring'''



       if _tqdm_active:
             return tqdm_lib.tqdm.get_lock()
a__						:				Optional[Any]           =    _tqdm_cls()





def     snake_case							(						)->     bool:







      """simple docstring"""
      global _tqdm_active
      return bool(_tqdm_active		)





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







      """simple docstring"""
      global _tqdm_active
      __A    		=     True





def     snake_case							(						)->     Optional[int]:







      """simple docstring"""
      global _tqdm_active
      __A    		=     False








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






