from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_tokenizers_available,
    is_torch_available,
)


lowerCAmelCase__					=				{
    'configuration_open_llama': ['OPEN_LLAMA_PRETRAINED_CONFIG_ARCHIVE_MAP', 'OpenLlamaConfig'],
}

try:
    if not is_sentencepiece_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    lowerCAmelCase__					=				['LlamaTokenizer']

try:
    if not is_tokenizers_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    lowerCAmelCase__					=				['LlamaTokenizerFast']

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    lowerCAmelCase__					=				[
        'OpenLlamaForCausalLM',
        'OpenLlamaModel',
        'OpenLlamaPreTrainedModel',
        'OpenLlamaForSequenceClassification',
    ]


if TYPE_CHECKING:
    from .configuration_open_llama import OPEN_LLAMA_PRETRAINED_CONFIG_ARCHIVE_MAP, OpenLlamaConfig

    try:
        if not is_sentencepiece_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from transformers import LlamaTokenizer

    try:
        if not is_tokenizers_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from transformers import LlamaTokenizerFast

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_open_llama import (
            OpenLlamaForCausalLM,
            OpenLlamaForSequenceClassification,
            OpenLlamaModel,
            OpenLlamaPreTrainedModel,
        )


else:
    import sys

    lowerCAmelCase__					=				_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)

from __future__ import annotations






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






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






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