output_description: Print N lines. In the i-th line, print `0` if Vertex i is the root of the
  original tree, and otherwise print the integer representing the parent of
  Vertex i in the original tree.
  
  Note that it can be shown that the original tree is uniquely determined.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M
      A_1 B_1
      :
      A_{N-1+M} B_{N-1+M}
attempt: class Graph:
      def __init__(self, n_vertices, edges, directed=True):
          self.n_vertices = n_vertices
          self.edges = edges
          self.directed = directed
  
      @property
      def adj(self):
          try:
              return self._adj
          except AttributeError:
              adj = [[] for _ in range(self.n_vertices)]
              if self.directed:
                  for u, v in self.edges:
                      adj[u].append(v)
              else:
                  for u, v in self.edges:
                      adj[u].append(v)
                      adj[v].append(u)
              self._adj = adj
              return adj
  
  
  max2 = lambda x, y: x if x > y else y
  min2 = lambda x, y: x if x < y else y
  
  import sys
  
  read = sys.stdin.buffer.read
  readline = sys.stdin.buffer.readline
  
  
  def solve(N, edges):
      adj = Graph(N, edges, directed=True).adj
      parent = [-1] * N
  
      # find root
      candidates = [True] * N
      for a, b in edges:
          candidates[b] = False
  
      root = next(v for v, f in enumerate(candidates) if f)
  
      q = [root]
      while q:
          nq = []
          for v in q:
              for u in adj[v]:
                  if parent[u] != v:
                      parent[u] = v
                      nq.append(u)
          q = nq
      return (p + 1 for p in parent)
  
  
  if __name__ == "__main__":
      N, M = map(int, readline().split())
      m = map(lambda x: int(x) - 1, read().split())
      edges = list(zip(m, m))
      print(*solve(N, edges), sep="\n")
  
problem_description: Statement
  
  There is a rooted tree (see Notes) with N vertices numbered 1 to N. Each of
  the vertices, except the root, has a directed edge coming from its parent.
  Note that the root may not be Vertex 1.
  
  Takahashi has added M new directed edges to this graph. Each of these M edges,
  u \rightarrow v, extends from some vertex u to its descendant v.
  
  You are given the directed graph with N vertices and N-1+M edges after
  Takahashi added edges. More specifically, you are given N-1+M pairs of
  integers, (A_1, B_1), ..., (A_{N-1+M}, B_{N-1+M}), which represent that the
  i-th edge extends from Vertex A_i to Vertex B_i.
  
  Restore the original rooted tree.
samples: [{"input": "3 1\n    1 2\n    1 3\n    2 3", "output": "0\n    1\n    2\n    \n\nThe graph in this input is shown below:\n\n![](https://img.atcoder.jp/nikkei2019-qual/ee05880ceecf703f656dd50bf22c573f.png)\n\nIt can be seen that this graph is obtained by adding the edge 1 \\rightarrow 3\nto the rooted tree 1 \\rightarrow 2 \\rightarrow 3.\n\n* * *"}, {"input": "6 3\n    2 1\n    2 3\n    4 1\n    4 2\n    6 1\n    2 6\n    4 6\n    6 5", "output": "6\n    4\n    2\n    0\n    6\n    2"}]