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
cnt = 0
while vst.any?{ |e| !e }
  rg.each_with_index do |arr, i|
    if arr.empty? && !vst[i]
      vst[i] = cnt
      g[i].each{|t| rg[t].delete(i)}
      break
    end
  end
  cnt += 1
end
vst.map.with_index{|e, i| [e, i]}.sort.each{|a| p a[1]}