require 'tsort'

class Hash
  include TSort
  alias tsort_each_node each_key
  def tsort_each_child(node, &block)
    fetch(node).each(&block)
  end
end

hash = Hash.new{|h,k| h[k] = []}
inv_hash = Hash.new{|h,k| h[k] = []}

nm = gets.chomp.split(" ").map(&:to_i)

for i in 0..nm[0]-2+nm[1]
  a = gets.chomp.split(" ").map(&:to_i)
  hash[a[1]] = [] if !hash[a[1]]
  hash[a[0]] << a[1]
  inv_hash[a[1]] << a[0]
end

tsort = hash.tsort

stack_hash = Hash.new{|h,k| h[k] = []}
final = Array.new(nm[0]+nm[1]-2)

for i in 0..tsort.length-1
  next if !inv_hash[tsort[i]]
  inv_hash[tsort[i]].each do |t|
    stack_hash[t] << tsort[i] if tsort[i]
  end
  stack_hash[tsort[i]].each do |t|
    final[t] = tsort[i] unless final[t]
  end
end

for i in 1..final.length-1
  final[i] = 0 if !final[i]
  puts final[i]
end