N,M = gets.split.map &:to_i
es = {}
rs = {}
(N+M-1).times{ n,m = gets.split.map &:to_i; es[n] ||= {}; rs[m] ||= {}; es[n][m] = rs[m][n] = 1 }
sorted = IO.popen("tsort", "r+") {|io|
  io.puts es.map{ |n,h| h.keys.map{ |m| [n,m] } }.flatten.join(" ")
  io.close_write
  io.readlines.join
}.split.map(&:to_i)

dp = Array.new(N+1,0)
sorted.each{ |n|
  (es[n] || {}).keys.each{ |m| dp[m] = dp[n] + 1 if dp[n] >= dp[m] }
}
puts (1..N).map{ |m|
  (rs[m] || {}).keys.find{ |n| dp[m] - 1 == dp[n] } || 0
}
