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: import sys
  import math
  import collections
  import itertools
  import array
  import inspect
  
  # Set max recursion limit
  sys.setrecursionlimit(1000000)
  
  
  # Debug output
  def chkprint(*args):
      names = {id(v): k for k, v in inspect.currentframe().f_back.f_locals.items()}
      print(", ".join(names.get(id(arg), "???") + " = " + repr(arg) for arg in args))
  
  
  # Binary converter
  def to_bin(x):
      return bin(x)[2:]
  
  
  def li_input():
      return [int(_) for _ in input().split()]
  
  
  def gcd(n, m):
      if n % m == 0:
          return m
      else:
          return gcd(m, n % m)
  
  
  def gcd_list(L):
      v = L[0]
  
      for i in range(1, len(L)):
          v = gcd(v, L[i])
  
      return v
  
  
  def lcm(n, m):
      return (n * m) // gcd(n, m)
  
  
  def lcm_list(L):
      v = L[0]
  
      for i in range(1, len(L)):
          v = lcm(v, L[i])
  
      return v
  
  
  # Width First Search (+ Distance)
  def wfs_d(D, N, K):
      """
      D: 隣接行列(距離付き)
      N: ノード数
      K: 始点ノード
      """
  
      dfk = [-1] * (N + 1)
      dfk[K] = 0
  
      cps = [(K, 0)]
      r = [False] * (N + 1)
      r[K] = True
      while len(cps) != 0:
          n_cps = []
          for cp, cd in cps:
              for i, dfcp in enumerate(D[cp]):
                  if dfcp != -1 and not r[i]:
                      dfk[i] = cd + dfcp
                      n_cps.append((i, cd + dfcp))
                      r[i] = True
  
          cps = n_cps[:]
  
      return dfk
  
  
  # Depth First Search (+Distance)
  def dfs_d(v, pre, dist):
      """
      v:  現在のノード
      pre: １つ前のノード
      dist: 現在の距離
  
      以下は別途用意する
      D: 隣接リスト(行列ではない)
      D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
      """
  
      global D
      global D_dfs_d
  
      D_dfs_d[v] = dist
  
      for next_v, d in D[v]:
          if next_v != pre:
              dfs_d(next_v, v, dist + d)
  
      return
  
  
  def sigma(N):
      ans = 0
      for i in range(1, N + 1):
          ans += i
      return ans
  
  
  def comb(n, r):
      if n - r < r:
          r = n - r
      if r == 0:
          return 1
      if r == 1:
          return n
  
      numerator = [n - r + k + 1 for k in range(r)]
      denominator = [k + 1 for k in range(r)]
  
      for p in range(2, r + 1):
          pivot = denominator[p - 1]
          if pivot > 1:
              offset = (n - r) % p
              for k in range(p - 1, r, p):
                  numerator[k - offset] /= pivot
                  denominator[k] /= pivot
  
      result = 1
      for k in range(r):
          if numerator[k] > 1:
              result *= int(numerator[k])
  
      return result
  
  
  def bisearch(L, target):
      low = 0
      high = len(L) - 1
  
      while low <= high:
          mid = (low + high) // 2
          guess = L[mid]
          if guess == target:
              return True
          elif guess < target:
              low = mid + 1
          elif guess > target:
              high = mid - 1
      if guess != target:
          return False
  
  
  # --------------------------------------------
  
  dp = None
  
  
  def sigma_(a, b, n):
      return (a + b) * n // 2
  
  
  def main():
      N, M = li_input()
      V = [li_input() for _ in range(N + M - 1)]
  
      # print("N,M", N, M)
      # print("V", V)
  
      Link = [[] for _ in range(N + 1)]
      iLink = [[] for _ in range(N + 1)]
  
      for v in V:
          sv, se = v
          Link[sv].append(se)
          iLink[se].append(sv)
  
      # 根を求める
      distV = []
      for v in V:
          distV.append(v[1])
  
      distV = list(set(distV))
      root = sigma_(1, N, N) - sum(distV)
  
      # print("root", root)
  
      A = [0] * N
  
      Layer = [[root]]
  
      parent_nodes = [root]
  
      i = 1
      while len(Layer[i - 1]) != 0:
          Layer.append([])
          new_parent_nodes = []
          for parent_node in parent_nodes:
              for l in Link[parent_node]:
                  Layer[i].append(l)
  
          parent_nodes = Layer[i]
          i += 1
  
      Layer = Layer[:-1]
  
      for i in range(len(Layer)):
          Layer[i] = list(set(Layer[i]))
      # print("Layer", Layer)
  
      X = [[False] * (N + 1) for _ in range(len(Layer))]
  
      for i, L in enumerate(Layer):
          for l in L:
              X[i][l] = True
  
      print(1)
  
      # i = len(Layer) - 1
      # while i >= 0:
      #     # print(Layer)
      #     L = Layer[i]
      #     for l in L:
  
      #         maybe_parents = iLink[l]
  
      #         for maybe_parent in maybe_parents:
      #             if X[i-1][maybe_parent]:
      #                 A[l-1] = maybe_parent
  
      #                 j = i - 1
      #                 while j >= 0:
      #                     Layer[j] = list(filter(lambda a:a != l, Layer[j]))
      #                     j -= 1
  
      #                 break
  
      #     i -= 1
  
      # for a in A:
      #     print(a)
  
  
  main()
  
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"}]