local n, m = io.read("*n", "*n")
local edge = {}
local pcnt = {}
local len = {}
for i = 1, n do
  edge[i] = {}
  pcnt[i] = 0
  len[i] = 0
end
local rawsrc, rawdst = {}, {}
for i = 1, n - 1 + m do
  local a, b = io.read("*n", "*n")
  table.insert(edge[a], b)
  pcnt[b] = pcnt[b] + 1
  rawsrc[i], rawdst[i] = a, b
end
local tasks = {}
for i = 1, n do
  if pcnt[i] == 0 then
    tasks[1] = i
    break
  end
end
local done = 0
while done < #tasks do
  done = done + 1
  local src = tasks[done]
  local l = len[src]
  local edgesrc = edge[src]
  for i = 1, #edgesrc do
    local dst = edgesrc[i]
    if len[dst] < len[src] + 1 then
      len[dst] = len[src] + 1
    end
    pcnt[dst] = pcnt[dst] - 1
    if pcnt[dst] == 0 then
      table.insert(tasks, dst)
    end
  end
end
local parent = {}
for i = 1, n do
  parent[i] = 0
end
for i = 1, n - 1 + m do
  local src, dst = rawsrc[i], rawdst[i]
  if len[src] + 1 == len[dst] then
    parent[dst] = src
  end
end
print(table.concat(parent, "\n"))
