import java.util.*

class Node(val Id:Int) {
    private var mEdgesTo:LinkedList<Node> = LinkedList()
    private var mCountEdgesFromOther:Int = 0
    companion object {
        fun SetEdge(from:Node, to:Node):Unit {
            from.mEdgesTo.push(to)
            ++to.mCountEdgesFromOther
        }
    }
    fun CanBeFirst():Boolean = mCountEdgesFromOther == 0
    fun UseNode():List<Node> {
        return mEdgesTo.filter { --it.mCountEdgesFromOther == 0}
    }
}
fun main(args:Array<String>):Unit{
    val (v, e) = readLine()!!.split(' ').map(String::toInt)
    val nodes = Array(v){Node(it)}
    for (i in 0 until e){
        val (s, t) = readLine()!!.split(' ').map(String::toInt)
        Node.SetEdge(nodes[s], nodes[t])
    }
    val canBeFirst = nodes.filter{it.CanBeFirst()}.toMutableList()
    while (!canBeFirst.isEmpty()){
        val first = canBeFirst.first()
        canBeFirst.removeAt(0)
        println(first.Id)
        canBeFirst += first.UseNode()
    }
}
