require 'set'
loop {
    n, m = gets.split.map &:to_i
    break if n == 0
    infected = Set[1]
    com = (1..m).map { gets.split.map &:to_i}.sort
    com.each{|_, i, j|
        if infected.include?(i)
            infected << j
        end
    }
    p infected.size
}