


"""simple docstring"""







from __future__ import annotations
def _A		(		lowercase						):







    """simple docstring"""
    global graph, reversed_graph, scc, component, visit, stack
    if visit[u]:
        return
    a											=True
    for v in graph[u]:
        dfs(lowercase						)
    stack.append(lowercase						)
def _A		(		lowercase						):







    """simple docstring"""
    global graph, reversed_graph, scc, component, visit, stack
    if visit[u]:
        return
    a											=True
    component.append(lowercase						)
    for v in reversed_graph[u]:
        dfsa(lowercase						)
def _A		(		):







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


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

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

       lowerCamelCase_  :  Any     		=    []
       lowerCamelCase_  :  Dict     		=    [False] * n
       lowerCamelCase_  :  int     		=    []
       lowerCamelCase_  :  List[str]     		=    []
       print(kosaraju())




def 						_UpperCAmelCase							( snake_case     ):





					"""simple docstring"""

					_lowerCAmelCase         =       str(snake_case     ).strip()
					if not bin_string:
										raise ValueError("""Empty string was passed to the function"""     )
					_lowerCAmelCase         =       bin_string[0] == """-"""
					if is_negative:
										_lowerCAmelCase         =       bin_string[1:]
					if not all(char in """01""" for char in bin_string     ):
										raise ValueError("""Non-binary value was passed to the function"""     )
					_lowerCAmelCase         =       0
					for char in bin_string:
										_lowerCAmelCase         =       2 * decimal_number + int(snake_case     )
					return -decimal_number if is_negative else decimal_number


if __name__ == "__main__":
	from doctest import testmod

	testmod()



