package com.uni.scala.coding

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.io.Source.stdin

object Main {

  // val solver = (_: List[String]) => ""
  val solver: List[String] => String = agc002b

  def main(args: Array[String]): Unit = {
    val ans = solver(read())
    println(ans)
  }

  def read(): List[String] = {
    stdin.getLines().toList
  }

  val agc002b: List[String] => String = (args: List[String]) => {
    val opList = args.drop(1).map(op => op.split(" ").map(x => x.toInt))
    val set = mutable.Set(1)
    val cntArray = {
      val tmp = ArrayBuffer[Int]()
      tmp ++= (0 to 100000).map(_ => 1)
      tmp
    }

    for (op <- opList) {
      val from = op(0)
      val to = op(1)
      cntArray(from) -= 1
      cntArray(to) += 1
      if (set.contains(from)) {
        set += to
        if (cntArray(from) == 0) {
          set -= from
        }
      }
    }

    set.size.toString
  }
}
