v, e = gets.split.map(&:to_i)
vst = [false]*v
g = v.times.map{[]}
rg = v.times.map{[]}
e.times do
  s,t = gets.split.map(&:to_i)
  g[s] << t
  rg[t] << s
end
arr = rg.map.with_index{|a, i| i if a.empty? }.compact
cnt = 0
while vst.any?{ |e| !e }
  i = arr.shift
  vst[i] = cnt
  g[i].each{|t| rg[t].delete(i); arr << t if rg[t].empty?}
  cnt += 1
end
vst.map.with_index{|e, i| [e, i]}.sort.each{|a| p a[1]}