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

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

que = parent.map.with_index{|v, i| v[0] == 0 ? i : nil}.compact
que.shift
topo = Array.new(n+1)
rtopo = []
i = 0
while now = que.shift
    topo[now] = i
    rtopo << now
    i += 1
    child[now].each do |x|
        parent[x][0] -= 1
        que << x if parent[x][0] == 0
    end
end

1.upto(n) do |i|
    parent[i] = parent[i][1].map{|e| topo[e]}.max
end

parent.shift
parent.each {|x| p x ? rtopo[x] : 0}