require 'tsort'

N, M = gets.split.map(&:to_i)

g = Hash.new
(1..N).each do |i|
  g[i] = []
end

(N - 1 + M).times do
  from, to = gets.split.map(&:to_i)
  g[from] << to
end

each_node = -> (&b) { g.each_key(&b) }
each_child = -> (n, &b) { g[n].each(&b) }
order = TSort.tsort(each_node, each_child).reverse

parent = Array.new(N + 1, -1)
queue = [[order.first, 0]]

until queue.empty?
  i, par = queue.shift

  parent[i] = par

  g[i].each do |j|
    queue << [j, i]
  end
end

puts [*1..N].map { |i| parent[i] }
