n, m = gets.split.map(&:to_i)
parent = Hash.new { |h, k| h[k] = [] }
(n + m - 1).times do
  a, b = gets.split.map(&:to_i)
  parent[b] << a
end

(1..n).each do |from|
  from.tapp
  queue = [[from, {}]]
  routes = []
  until queue.empty?
    pos, route = queue.shift
    if parent[pos].empty?
      routes << route
    end
    parent[pos].each do |pr|
      r = route.dup
      r[pos] = pr
      queue << [pr, r]
    end
  end
  ok = routes.pop
  routes.each do |route|
    route.each do |b, a|
      if ok[b] != a
        parent[b].delete(a)
      end
    end
  end
end

(1..n).each do |i|
  puts(parent[i].first || 0)
end