Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		n, m := io.NextInt(), io.NextInt()
		if n == 0 {
			break
		}
		dat := make([]Dat, m)
		for i := 0; i < m; i++ {
			dat[i] = Dat{io.NextInt(), io.NextInt(), io.NextInt()}
		}
		sort.Slice(dat, func(i, j int) bool { return dat[i].t < dat[j].t })
		infected := make([]bool, n+1)
		infected[1] = true
		for i := 0; i < m; i++ {
			infected[dat[i].d] = infected[dat[i].d] || infected[dat[i].s]
		}
		cnt := 0
		for i := 0; i <= n; i++ {
			if infected[i] {
				cnt++
			}
		}
		io.Println(cnt)
	}
}

type Dat struct {
	t, s, d int
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := make([]interface{}, 0, len(a))
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := make([]interface{}, 0, len(a))
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

Python: while True:
    N,M = map(int,input().split())
    if N == M == 0: break
    logs = []
    for i in range(M):
        t,s,d = map(int,input().split())
        s,d = s-1,d-1
        logs.append((t,s,d))
    infected = [0 for i in range(N)]
    infected[0] = 1
    for t,s,d in sorted(logs):
        if infected[s]:
            infected[d] = 1
    print(sum(infected))

Python: # -*- coding: utf-8 -*-
"""
Created on Tue Jun 14 15:56:37 2016

"""
while True:
    N, M = map(int, input().split())
    if N == M == 0:
        break
    
    PCs = [False] * N
    PCs[0] = True
    Packets = {}
    for _ in range(M):
        t, s, d = map(int, input().split())
        Packets[t] = (s, d)
    
    for key in sorted(Packets):
        if PCs[Packets[key][0] - 1] == True:
            PCs[Packets[key][1] - 1] = True
#            print('PC'+str(Packets[key][1])+' is infected')
            
    print(PCs.count(True))

Python: import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        n,m = LI()
        if n == 0 and m == 0:
            break
        a = [LI() for _ in range(m)]
        a.sort()
        u = set([1])
        for t,s,d in a:
            if s in u:
                u.add(d)

        rr.append(len(u))

    return '\n'.join(map(str, rr))


print(main())

Python: while True:
    n, m = map(int, input().split())
    if n == m == 0:
        break

    data = [list(map(int, input().split())) for i in range(m)]

    data.sort()
    infect = [False for i in range(n + 1)]
    infect[1] = True
    for t, s, d in data:
        if infect[s]:
            infect[d] = True

    print(infect.count(True))

Python: while 1:
    n,m=map(int,input().split())
    if n+m==0:break
    a=[1]+[0]*(n-1)
    b={}
    for _ in range(m):t,s,d=map(int,input().split());b[t]=(s,d)
    for x in sorted(b):
        if a[b[x][0]-1]:a[b[x][1]-1]=1
    print(sum(a))