N,M = gets.split.map(&:to_i)
es = (0..N).map{ [] }
rs = (0..N).map{ [] }
(N+M-1).times{
  a,b = gets.split.map(&:to_i)
  es[a] << b
  rs[b] << a
}
Root = (1..N).find{ |n| rs[n].size == 0 }
dp = Array.new(N+1, 0)

nodes = [Root]
while n = nodes.pop
  v = dp[n] + 1
  es[n].each{ |m|
    nodes << m
    dp[m] = v if v > dp[m]
  }
end

puts (1..N).map{ |n|
  next 0 if n == Root
  v = dp[n]
  rs[n].find{ |m| v - dp[m] == 1 }
}