fun main(args : Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val boxes = Array(n) {Box(false, 1)}
    boxes[0].hasRed = true

    repeat(m) {
        val (x, y) = readLine()!!.split(" ").map { it.toInt()-1 }
        if (boxes[x].cnt > 0) {
            boxes[x].cnt -= 1
            boxes[y].cnt++

            if (boxes[x].hasRed) {
                boxes[y].hasRed = true
            }
            if (boxes[x].cnt == 0) {
                boxes[x].hasRed = false
            }
        }
    }

    println(boxes.count { it.hasRed })
}

data class Box(var hasRed: Boolean, var cnt: Int)