





from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


UpperCAmelCase						:       int        =					{
    'configuration_mobilenet_v1': [
        'MOBILENET_V1_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'MobileNetV1Config',
        'MobileNetV1OnnxConfig',
    ],
}

try:
				if not is_vision_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				UpperCAmelCase						:       List[Any]        =					['MobileNetV1FeatureExtractor']
				UpperCAmelCase						:       List[str]        =					['MobileNetV1ImageProcessor']

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				UpperCAmelCase						:       Tuple        =					[
				    'MOBILENET_V1_PRETRAINED_MODEL_ARCHIVE_LIST',
				    'MobileNetV1ForImageClassification',
				    'MobileNetV1Model',
				    'MobileNetV1PreTrainedModel',
				    'load_tf_weights_in_mobilenet_v1',
				]


if TYPE_CHECKING:
				from .configuration_mobilenet_va import (
				    MOBILENET_V1_PRETRAINED_CONFIG_ARCHIVE_MAP,
				    MobileNetVaConfig,
				    MobileNetVaOnnxConfig,
				)

				try:
								if not is_vision_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .feature_extraction_mobilenet_va import MobileNetVaFeatureExtractor
								from .image_processing_mobilenet_va import MobileNetVaImageProcessor

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_mobilenet_va import (
								    MOBILENET_V1_PRETRAINED_MODEL_ARCHIVE_LIST,
								    MobileNetVaForImageClassification,
								    MobileNetVaModel,
								    MobileNetVaPreTrainedModel,
								    load_tf_weights_in_mobilenet_va,
								)


else:
				import sys

				UpperCAmelCase						:       Union[str, Any]        =					_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)











from __future__ import annotations







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







def 			_SCREAMING_SNAKE_CASE    (       a  )				->				Optional[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 			_SCREAMING_SNAKE_CASE    (       )				->				Optional[int]:
					global graph, reversed_graph, scc, component, visit, stack
					for i in range(a  ):
										dfs(a  )
					__A     :						str          =    [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						:       List[str]        =					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						:       int        =					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())




