from __future__ import annotations

import sys
class        a_				:






 '''simple docstring'''






 def __init__(    self      :						Union[str, Any]    ,					lowercase__      :						str    ,					lowercase__      :						int):







        '''simple docstring'''



        lowerCAmelCase__  			=      letter
        lowerCAmelCase__  			=      freq
        lowerCAmelCase__  			=      {}




 def __repr__(    self      :						Any):







        '''simple docstring'''



        return F'''{self.letter}:{self.freq}'''






class        a_				:






 '''simple docstring'''






 def __init__(    self      :						Dict    ,					lowercase__      :						int    ,					lowercase__      :						Letter | TreeNode    ,					lowercase__      :						Letter | TreeNode):







        '''simple docstring'''



        lowerCAmelCase__  			=      freq
        lowerCAmelCase__  			=      left
        lowerCAmelCase__  			=      right






def    __lowerCamelCase	(		lowerCAmelCase__			):
       lowerCAmelCase__  			=      {}
       with open(SCREAMING_SNAKE_CASE__			) as f:
              while True:
                     lowerCAmelCase__  			=      f.read(1			)
                     if not c:
                            break
                     lowerCAmelCase__  			=      chars[c] + 1 if c in chars else 1
       return sorted((Letter(SCREAMING_SNAKE_CASE__			,						SCREAMING_SNAKE_CASE__			) for c, f in chars.items())			,						key=lambda lowerCAmelCase__			: x.freq			)






def    __lowerCamelCase	(		lowerCAmelCase__			):
       lowerCAmelCase__  			=      letters  # type: ignore
       while len(SCREAMING_SNAKE_CASE__			) > 1:
              lowerCAmelCase__  			=      response.pop(0			)
              lowerCAmelCase__  			=      response.pop(0			)
              lowerCAmelCase__  			=      left.freq + right.freq
              lowerCAmelCase__  			=      TreeNode(SCREAMING_SNAKE_CASE__			,						SCREAMING_SNAKE_CASE__			,						SCREAMING_SNAKE_CASE__			)
              response.append(SCREAMING_SNAKE_CASE__			)
              response.sort(key=lambda lowerCAmelCase__			: x.freq			)
       return response[0]






def    __lowerCamelCase	(		lowerCAmelCase__			,						lowerCAmelCase__			):


       if isinstance(SCREAMING_SNAKE_CASE__			,						SCREAMING_SNAKE_CASE__			):
              lowerCAmelCase__  			=      bitstring
              return [root]
       lowerCAmelCase__  			=      root  # type: ignore
       lowerCAmelCase__  			=      []
       letters += traverse_tree(treenode.left			,						bitstring + '0'			)
       letters += traverse_tree(treenode.right			,						bitstring + '1'			)
       return letters






def    __lowerCamelCase	(		lowerCAmelCase__			):
       lowerCAmelCase__  			=      parse_file(SCREAMING_SNAKE_CASE__			)
       lowerCAmelCase__  			=      build_tree(SCREAMING_SNAKE_CASE__			)
       lowerCAmelCase__  			=      {
           k: v for letter in traverse_tree(SCREAMING_SNAKE_CASE__			,						''			) for k, v in letter.bitstring.items()
       }
       print(F'''Huffman Coding  of {file_path}: '''			)
       with open(SCREAMING_SNAKE_CASE__			) as f:
              while True:
                     lowerCAmelCase__  			=      f.read(1			)
                     if not c:
                            break
                     print(letters[c]			,						end=' '			)
       print()


if __name__ == "__main__":
    # pass the file path to the huffman function
    huffman(sys.argv[1])

from __future__ import annotations






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






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






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


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

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

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