class Node
  attr_accessor :child, :parent
  def initialize
    @child = {}
    @parent = {}
  end
end

v, e = gets.split.map(&:to_i)
g = Array.new(v){Node.new}

edges = {}
e.times{
  s, t = gets.split.map(&:to_i)
  g[s].child[t] = 1
  g[t].parent[s] = 1
  edges[[s,t]] = true
}

list = []
start = []
v.times{|i|
  if g[i].parent.size == 0
    start << i
  end
}

while start.size > 0
  n = start.shift
  list << n
  ed = g[n].child.clone
  ed.each{|m, val|
    g[n].child.delete(m)
    g[m].parent.delete(n)
    edges.delete([n,m])
    start << m if g[m].parent.size == 0
  }
end

puts list