
from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


UpperCAmelCase__						:	Any	     = {
    'configuration_decision_transformer': [
        'DECISION_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'DecisionTransformerConfig',
    ],
}

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   UpperCAmelCase__						:	Optional[Any]	     = [
       'DECISION_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST',
       'DecisionTransformerGPT2Model',
       'DecisionTransformerGPT2PreTrainedModel',
       'DecisionTransformerModel',
       'DecisionTransformerPreTrainedModel',
   ]


if TYPE_CHECKING:
   from .configuration_decision_transformer import (
       DECISION_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP,
       DecisionTransformerConfig,
   )

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_decision_transformer import (
          DECISION_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
          DecisionTransformerGPTaModel,
          DecisionTransformerGPTaPreTrainedModel,
          DecisionTransformerModel,
          DecisionTransformerPreTrainedModel,
      )


else:
   import sys

   UpperCAmelCase__						:	Optional[Any]	     = _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)





from __future__ import annotations






def     lowerCamelCase__				(   a ) ->  Union[str, Any]:
   global graph, reversed_graph, scc, component, visit, stack
   if visit[u]:
      return
   _A:    Optional[Any]						     =			True
   for v in graph[u]:
      dfs(a )
   stack.append(a )






def     lowerCamelCase__				(   a ) ->  List[Any]:
   global graph, reversed_graph, scc, component, visit, stack
   if visit[u]:
      return
   _A:    str						     =			True
   component.append(a )
   for v in reversed_graph[u]:
      dfsa(a )






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


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

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

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



