





from collections import OrderedDict
from typing import Any, List, Mapping, Optional

from ... import PretrainedConfig, PreTrainedTokenizer
from ...onnx import OnnxConfig, PatchingSpec
from ...utils import TensorType, is_torch_available, logging


UpperCAmelCase						:       Any        =					logging.get_logger(__name__)

UpperCAmelCase						:       str        =					{
    '''microsoft/layoutlm-base-uncased''': (
        '''https://huggingface.co/microsoft/layoutlm-base-uncased/resolve/main/config.json'''
    ),
    '''microsoft/layoutlm-large-uncased''': (
        '''https://huggingface.co/microsoft/layoutlm-large-uncased/resolve/main/config.json'''
    ),
}





class 						_A( snake_case__       ):


				"""simple docstring"""


				UpperCamelCase   :  List[Any]    =     '''layoutlm'''



				def __init__(      self					, _A=30522					, _A=768					, _A=12					, _A=12					, _A=3072					, _A="gelu"					, _A=0.1					, _A=0.1					, _A=512					, _A=2					, _A=0.0_2					, _A=1e-1_2					, _A=0					, _A="absolute"					, _A=True					, _A=1024					, **_A					, ):
									super().__init__(pad_token_id=_A					, **_A					)
									__A     :						Dict          =    vocab_size
									__A     :						Union[str, Any]          =    hidden_size
									__A     :						str          =    num_hidden_layers
									__A     :						List[Any]          =    num_attention_heads
									__A     :						List[str]          =    hidden_act
									__A     :						Optional[Any]          =    intermediate_size
									__A     :						Optional[int]          =    hidden_dropout_prob
									__A     :						Dict          =    attention_probs_dropout_prob
									__A     :						List[str]          =    max_position_embeddings
									__A     :						Optional[int]          =    type_vocab_size
									__A     :						Optional[Any]          =    initializer_range
									__A     :						int          =    layer_norm_eps
									__A     :						Tuple          =    position_embedding_type
									__A     :						int          =    use_cache
									__A     :						Optional[Any]          =    max_ad_position_embeddings





class 						_A( snake_case__       ):


				"""simple docstring"""


				def __init__(      self					, _A					, _A = "default"					, _A = None					, ):
									super().__init__(_A					, task=_A					, patching_specs=_A					)
									__A     :						List[Any]          =    config.max_ad_position_embeddings - 1



				@property
				def  UpperCAmelCase_		(      self					):
									return OrderedDict(
									    [
									        ('input_ids', {0: 'batch', 1: 'sequence'}),
									        ('bbox', {0: 'batch', 1: 'sequence'}),
									        ('attention_mask', {0: 'batch', 1: 'sequence'}),
									        ('token_type_ids', {0: 'batch', 1: 'sequence'}),
									    ]					)





				def  UpperCAmelCase_		(      self					, _A					, _A = -1					, _A = -1					, _A = False					, _A = None					, ):
									__A     :						Optional[int]          =    super().generate_dummy_inputs(
									    _A					, batch_size=_A					, seq_length=_A					, is_pair=_A					, framework=_A					)

									# Generate a dummy bbox
									__A     :						int          =    [48, 84, 73, 128]

									if not framework == TensorType.PYTORCH:
														raise NotImplementedError('Exporting LayoutLM to ONNX is currently only supported for PyTorch.'					)

									if not is_torch_available():
														raise ValueError('Cannot generate dummy inputs without PyTorch installed.'					)
									import torch

									__A   ,    __A     :						List[str]          =    input_dict['input_ids'].shape
									__A     :						Optional[int]          =    torch.tensor([*[box] * seq_length]					).tile(_A					, 1					, 1					)
									return input_dict











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




