v, e = gets.split.map(&:to_i)
ret = []
set = Array.new(v){ |i| i }
g = Array.new(v){ Array.new }
rg = Array.new(v){ Array.new }
e.times do
  s,t = gets.split.map(&:to_i)
  g[s] << t
  rg[t] << s
end
empset = rg.map.each_with_index{|a, i| i if a.empty? }.compact
until set.empty?
  n = empset.shift
  set.delete(n)
  ret << n
  g[n].each do |m|
    rg[m].delete(n)
    if rg[m].empty?
      set << m
      empset << m
    end
  end
end
ret.each{|v| p v}