def lower_bound(arr, v)
  l = -1
  r = arr.size
  while l + 1 < r
    m = (l + r) / 2
    if arr[m][0] < v then l = m
    else r = m
    end
  end
  r
end

loop do
  n, m = gets.split.map(&:to_i)
  break if n == 0
  pcs = (n + 1).times.map{ [] }
  m.times do
    t, s, d = gets.split.map(&:to_i)
    pcs[s] <<  [t, d]
  end
  pcs.map!{ |time| time.sort }
  infected_pc = [false] * (n + 1)
  infected_pc[1] = true
  queue = [[0, 1]]
  until queue.empty?
    time, pc = queue.shift
    idx = lower_bound(pcs[pc], time)
    pcs[pc][idx..-1].each do |t, p|
      unless infected_pc[p]
        infected_pc[p] = true
      end
      queue << [t, p]
    end
  end
  puts infected_pc.count(true)
end