require 'tsort'

V, E = gets.split.map(&:to_i)
g = Hash.new

(0...V).each do |i|
  g[i] = []
end

E.times do
  from, to = gets.split.map(&:to_i)
  g[from] << to
end

each_node = -> (&b) { g.each_key(&b) }
each_child = -> (n, &b) { g[n].each(&b) }
order = TSort.tsort(each_node, each_child).reverse

puts order

