






from __future__ import annotations


def __A       ( __lowerCAmelCase      )->    List[str]:





						"""simple docstring"""



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


def __A       ( __lowerCAmelCase      )->    Optional[Any]:





						"""simple docstring"""



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


def __A       ( )->    int:





						"""simple docstring"""



						global graph, reversed_graph, scc, component, visit, stack
						for i in range(__lowerCAmelCase      ):
												dfs(__lowerCAmelCase      )
						_UpperCAmelCase							   =     [False] * n
						for i in stack[::-1]:
												if visit[i]:
																		continue
												_UpperCAmelCase							   =     []
												dfsa(__lowerCAmelCase      )
												scc.append(__lowerCAmelCase      )
						return scc


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

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

		_a       =    []
		_a       =    [False] * n
		_a       =    []
		_a       =    []
		print(kosaraju())








def __A       ( __lowerCAmelCase = 100					,						__lowerCAmelCase = 100      )->    int:





						"""simple docstring"""



						return max(
						    sum(int(__lowerCAmelCase      ) for x in str(base**power      )      )
						    for base in range(__lowerCAmelCase      )
						    for power in range(__lowerCAmelCase      )      )


# Tests
if __name__ == "__main__":
		import doctest

		doctest.testmod()
