loop do
    n, m = gets.split.map(&:to_i)
    break if n == 0 && m == 0
    d = m.times.map{gets.split.map(&:to_i)}
    d = d.sort
    inf = Array.new(n+1,false)
    inf[1] = true
    count = 1
    d.each do |dd|
        if inf[dd[1]] && !inf[dd[2]]
            inf[dd[2]] = true
            count += 1
        end
    end
    puts count
end