n, m = gets.split.map(&:to_i)

par = Array.new(n+1) {[0, []]}
chi = Array.new(n+1) {[]}
(n-1+m).times do
    a, b = gets.split.map(&:to_i)
    chi[a] << b
    par[b][0] += 1
    par[b][1] << a
end

que = [par.rindex{|e| e[0] == 0}]
t = Array.new(n+1)
rt = []
i = -1
while now = que.shift
    t[now] = i += 1
    rt << now
    chi[now].each {|x| (par[x][0] -= 1).zero? and que << x}
end

1.upto(n) {|i| p rt[0] == i ? 0 : rt[par[i][1].map{|e| t[e]}.max]}