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

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

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