'''simple docstring'''




import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging


_lowercase		:					Union[str, Any]													=		logging.get_logger(__name__)

_lowercase		:					List[Any]													=		{
    "facebook/sam-vit-huge": "https://huggingface.co/facebook/sam-vit-huge/resolve/main/config.json",
    "facebook/sam-vit-large": "https://huggingface.co/facebook/sam-vit-large/resolve/main/config.json",
    "facebook/sam-vit-base": "https://huggingface.co/facebook/sam-vit-base/resolve/main/config.json",
}





class        __magic_name__		(       _UpperCAmelCase):







			def __init__(      self							:    int							,     lowercase_							:    List[Any]=256							,     lowercase_							:    Tuple=1024							,     lowercase_							:    str=16							,     lowercase_							:    Dict=16							,     lowercase_							:    List[str]=4							,     lowercase_							:    Union[str, Any]="gelu"							,     lowercase_							:    Any=1E-6							,     **lowercase_							:    Tuple							,     ):
										super().__init__(**lowercase_       )
										lowercase_   :     Optional[Any]									=			hidden_size
										lowercase_   :     Dict									=			image_size
										lowercase_   :     Any									=			patch_size
										lowercase_   :     Optional[Any]									=			image_size // patch_size
										lowercase_   :     Union[str, Any]									=			mask_input_channels
										lowercase_   :     Optional[int]									=			num_point_embeddings
										lowercase_   :     int									=			hidden_act
										lowercase_   :     Optional[Any]									=			layer_norm_eps





class        __magic_name__		(       _UpperCAmelCase):







			def __init__(      self							:    Any							,     lowercase_							:    Any=256							,     lowercase_							:    int="relu"							,     lowercase_							:    Optional[Any]=2048							,     lowercase_							:    str=2							,     lowercase_							:    List[str]=8							,     lowercase_							:    Dict=2							,     lowercase_							:    Optional[Any]=3							,     lowercase_							:    Optional[Any]=3							,     lowercase_							:    Optional[Any]=256							,     lowercase_							:    Tuple=1E-6							,     **lowercase_							:    int							,     ):
										super().__init__(**lowercase_       )
										lowercase_   :     Optional[int]									=			hidden_size
										lowercase_   :     int									=			hidden_act
										lowercase_   :     Optional[Any]									=			mlp_dim
										lowercase_   :     Union[str, Any]									=			num_hidden_layers
										lowercase_   :     List[Any]									=			num_attention_heads
										lowercase_   :     Tuple									=			attention_downsample_rate
										lowercase_   :     Optional[int]									=			num_multimask_outputs
										lowercase_   :     str									=			iou_head_depth
										lowercase_   :     Dict									=			iou_head_hidden_dim
										lowercase_   :     Union[str, Any]									=			layer_norm_eps





class        __magic_name__		(       _UpperCAmelCase):







			def __init__(      self							:    int							,     lowercase_							:    Tuple=768							,     lowercase_							:    Optional[Any]=256							,     lowercase_							:    Tuple=12							,     lowercase_							:    Optional[Any]=12							,     lowercase_							:    Optional[Any]=3							,     lowercase_							:    str=1024							,     lowercase_							:    Optional[int]=16							,     lowercase_							:    Any="gelu"							,     lowercase_							:    Dict=1E-06							,     lowercase_							:    str=0.0							,     lowercase_							:    Union[str, Any]=1E-10							,     lowercase_							:    List[Any]=True							,     lowercase_							:    Union[str, Any]=4.0							,     lowercase_							:    Any=True							,     lowercase_							:    Any=True							,     lowercase_							:    Any=14							,     lowercase_							:    int=[2, 5, 8, 11]							,     lowercase_							:    Tuple=128							,     lowercase_							:    Dict=None							,     **lowercase_							:    Dict							,     ):
										super().__init__(**lowercase_       )

										lowercase_   :     List[str]									=			hidden_size
										lowercase_   :     Union[str, Any]									=			output_channels
										lowercase_   :     str									=			num_hidden_layers
										lowercase_   :     str									=			num_attention_heads
										lowercase_   :     List[str]									=			num_channels
										lowercase_   :     str									=			image_size
										lowercase_   :     Tuple									=			patch_size
										lowercase_   :     Dict									=			hidden_act
										lowercase_   :     Any									=			layer_norm_eps
										lowercase_   :     Tuple									=			attention_dropout
										lowercase_   :     Any									=			initializer_range
										lowercase_   :     int									=			qkv_bias
										lowercase_   :     Any									=			mlp_ratio
										lowercase_   :     Optional[int]									=			use_abs_pos
										lowercase_   :     Union[str, Any]									=			use_rel_pos
										lowercase_   :     List[str]									=			window_size
										lowercase_   :     Optional[Any]									=			global_attn_indexes
										lowercase_   :     int									=			num_pos_feats
										lowercase_   :     List[Any]									=			int(hidden_size * mlp_ratio       ) if mlp_dim is None else mlp_dim





class        __magic_name__		(       _UpperCAmelCase):
			UpperCamelCase__							=			'''sam'''
			UpperCamelCase__							=			True







			def __init__(      self							:    Any							,     lowercase_							:    Any=None							,     lowercase_							:    str=None							,     lowercase_							:    List[str]=None							,     lowercase_							:    int=0.02							,     **lowercase_							:    str							,     ):
										super().__init__(**lowercase_       )
										lowercase_   :     Tuple									=			vision_config if vision_config is not None else {}
										lowercase_   :     Dict									=			prompt_encoder_config if prompt_encoder_config is not None else {}
										lowercase_   :     List[str]									=			mask_decoder_config if mask_decoder_config is not None else {}

										if isinstance(lowercase_							,     lowercase_       ):
																	lowercase_   :     Any									=			vision_config.to_dict()
										if isinstance(lowercase_							,     lowercase_       ):
																	lowercase_   :     Dict									=			prompt_encoder_config.to_dict()
										if isinstance(lowercase_							,     lowercase_       ):
																	lowercase_   :     Tuple									=			mask_decoder_config.to_dict()

										lowercase_   :     int									=			SamVisionConfig(**lowercase_       )
										lowercase_   :     str									=			SamPromptEncoderConfig(**lowercase_       )
										lowercase_   :     Any									=			SamMaskDecoderConfig(**lowercase_       )
										lowercase_   :     Dict									=			initializer_range







			def       SCREAMING_SNAKE_CASE_	(      self							:    List[str]       ):
										lowercase_   :     List[Any]									=			copy.deepcopy(self.__dict__       )
										lowercase_   :     Dict									=			self.vision_config.to_dict()
										lowercase_   :     str									=			self.prompt_encoder_config.to_dict()
										lowercase_   :     Optional[int]									=			self.mask_decoder_config.to_dict()
										lowercase_   :     Union[str, Any]									=			self.__class__.model_type
										return output






'''simple docstring'''




from __future__ import annotations




def 				lowerCamelCase      ( UpperCAmelCase__			:   str					)     -> Any:
							global graph, reversed_graph, scc, component, visit, stack
							if visit[u]:
														return
							lowercase_   :     int									=			True
							for v in graph[u]:
														dfs(UpperCAmelCase__					)
							stack.append(UpperCAmelCase__					)




def 				lowerCamelCase      ( UpperCAmelCase__			:   int					)     -> str:
							global graph, reversed_graph, scc, component, visit, stack
							if visit[u]:
														return
							lowercase_   :     Tuple									=			True
							component.append(UpperCAmelCase__					)
							for v in reversed_graph[u]:
														dfsa(UpperCAmelCase__					)




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


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

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

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





