fun main(args: Array<String>?): Unit {
    while(true){
        val (n, m) = readLine()!!.trim().split(' ').map(String::toInt)
        if (n == 0 && m == 0) return
        val computers = BooleanArray(n){false}
        computers[0] = true
        val record = Array(m){
            val (t, s, d) = readLine()!!.trim().split(' ').map{it.toInt() - 1}
            Triple(t, s, d)
        }.sortedBy(Triple<Int, *, *>::first)
        for ((_, s, d) in record) {
            computers[d] = computers[s] || computers[d]
        }
        println(computers.count{it})
    }
}
