n, m = gets.split.map(&:to_i)
parents = {}
children = {}
# まずは性能を考慮せずに、親子をマッピングして作ってみる
(n + m).times do |i|
  parent, child = gets.split.map(&:to_i)
  if parents[child]
    parents[child].push parent
  else
    parents[child] = [ parent ]
  end
  if children[parent]
    children[parent].push child
  else
    children[parent] = [ child ]
  end
end

root = nil
n.times do |i|
  tmp = i + 1
  unless parents[tmp]
    root = tmp
    break
  end
end
tmp_root = [ root ]


nodes = []
levels = { 0 => tmp_root }
level = 0
node_level_hash = {}
node_level_hash[root] = 0
while true
  nodes.concat levels[level]
  levels[level + 1] = []
  break_flg = true
  levels[level].each do |x|
    if children[x]
      children[x].each do |c|
        break_flg = false
        if parents[c].all?{|p| nodes.include?(p)}
          levels[level + 1].push c 
          node_level_hash[c] = level + 1
        end
      end
    end
  end
  break if break_flg
  level += 1
end

n.times do |i|
  tmp = i + 1
  if parents[tmp]
    puts "#{parents[tmp].find{ |p| node_level_hash[p] == (node_level_hash[tmp] - 1)}}"
  else
    puts "0"
  end
end
