v, e = gets.split.map(&:to_i)
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
until arr.empty?
  s = arr.shift
  p s
  g[s].each{|t| rg[t].delete(s); arr << t if rg[t].empty?}
end