'''simple docstring'''




from __future__ import annotations




def 				lowerCamelCase      ( UpperCAmelCase__			:   str , UpperCAmelCase__			:   dict[str, str]					)     -> str:
							lowercase_		,		lowercase_		,		lowercase_   :     Union[str, Any]									=			"""""", """""", """"""
							lowercase_   :     Tuple									=			[]

							for character in message_part:
														tmp.append(character_to_number[character]					)

							for each in tmp:
														one += each[0]
														two += each[1]
														three += each[2]

							return one + two + three




def 				lowerCamelCase      ( UpperCAmelCase__			:   str , UpperCAmelCase__			:   dict[str, str]					)     -> tuple[str, str, str]:
							lowercase_		,		lowercase_   :     Union[str, Any]									=			"""""", """"""
							lowercase_   :     Any									=			[]

							for character in message_part:
														this_part += character_to_number[character]

							for digit in this_part:
														tmp += digit
														if len(UpperCAmelCase__					) == len(UpperCAmelCase__					):
																					result.append(UpperCAmelCase__					)
																					lowercase_   :     Optional[int]									=			""""""

							return result[0], result[1], result[2]




def 				lowerCamelCase      ( UpperCAmelCase__			:   str , UpperCAmelCase__			:   str					)     -> tuple[str, str, dict[str, str], dict[str, str]]:
							# Validate message and alphabet, set to upper and remove spaces
							lowercase_   :     List[Any]									=			alphabet.replace(""" """ , """"""					).upper()
							lowercase_   :     Optional[int]									=			message.replace(""" """ , """"""					).upper()

							# Check length and characters
							if len(UpperCAmelCase__					) != 27:
														raise KeyError("""Length of alphabet has to be 27."""					)
							for each in message:
														if each not in alphabet:
																					raise ValueError("""Each message character has to be included in alphabet!"""					)

    # Generate dictionares
							lowercase_   :     str									=			(
							    """111""",
							    """112""",
							    """113""",
							    """121""",
							    """122""",
							    """123""",
							    """131""",
							    """132""",
							    """133""",
							    """211""",
							    """212""",
							    """213""",
							    """221""",
							    """222""",
							    """223""",
							    """231""",
							    """232""",
							    """233""",
							    """311""",
							    """312""",
							    """313""",
							    """321""",
							    """322""",
							    """323""",
							    """331""",
							    """332""",
							    """333""",
							)
							lowercase_   :     str									=			{}
							lowercase_   :     List[str]									=			{}
							for letter, number in zip(UpperCAmelCase__ , UpperCAmelCase__					):
														lowercase_   :     List[str]									=			number
														lowercase_   :     Any									=			letter

							return message, alphabet, character_to_number, number_to_character




def 				lowerCamelCase      ( UpperCAmelCase__			:   str , UpperCAmelCase__			:   str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ." , UpperCAmelCase__			:   int = 5					)     -> str:
							lowercase_		,		lowercase_		,		lowercase_		,		lowercase_   :     Dict									=			__prepare(
							    UpperCAmelCase__ , UpperCAmelCase__					)
							lowercase_		,		lowercase_   :     int									=			"""""", """"""

							for i in range(0 , len(UpperCAmelCase__					) + 1 , UpperCAmelCase__					):
														encrypted_numeric += __encrypt_part(
														    message[i : i + period] , UpperCAmelCase__					)

							for i in range(0 , len(UpperCAmelCase__					) , 3					):
														encrypted += number_to_character[encrypted_numeric[i : i + 3]]

							return encrypted




def 				lowerCamelCase      ( UpperCAmelCase__			:   str , UpperCAmelCase__			:   str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ." , UpperCAmelCase__			:   int = 5					)     -> str:
							lowercase_		,		lowercase_		,		lowercase_		,		lowercase_   :     Tuple									=			__prepare(
							    UpperCAmelCase__ , UpperCAmelCase__					)
							lowercase_   :     Union[str, Any]									=			[]
							lowercase_   :     Tuple									=			""""""

							for i in range(0 , len(UpperCAmelCase__					) + 1 , UpperCAmelCase__					):
														lowercase_		,		lowercase_		,		lowercase_   :     Union[str, Any]									=			__decrypt_part(message[i : i + period] , UpperCAmelCase__					)

														for j in range(0 , len(UpperCAmelCase__					)					):
																					decrypted_numeric.append(a[j] + b[j] + c[j]					)

							for each in decrypted_numeric:
														decrypted += number_to_character[each]

							return decrypted


if __name__ == "__main__":
						_lowercase		:					Optional[int]													=		"DEFEND THE EAST WALL OF THE CASTLE."
						_lowercase		:					Dict													=		encrypt_message(msg, "EPSDUCVWYM.ZLKXNBTFGORIJHAQ")
						_lowercase		:					List[Any]													=		decrypt_message(encrypted, "EPSDUCVWYM.ZLKXNBTFGORIJHAQ")
						print(f"""Encrypted: {encrypted}\nDecrypted: {decrypted}""")






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





