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)
}

C++: #include<iostream>
#include<set>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
class state{
public:
  int t,s,d;
  bool operator<(const state & a)const{
    return t < a.t;
  }
};

main(){
  int n,m;
  while(cin>>n>>m && n){
    state in[m];
    rep(i,m)cin>>in[i].t>>in[i].s>>in[i].d;
    sort(in,in+m);
    set<int> S;
    S.insert(1);
    rep(i,m){
      if ( S.find(in[i].s)!=S.end())S.insert(in[i].d);
    }
    cout <<S.size() << endl;
  }
  return false;
}

C++: #include <iostream>
using namespace std;
int main(){
	/*int n,m;
	while(cin>>n>>m){
		if(n==0&&m==0) break;
		int a[m][3];
		for(int i=0;i<m;i++){
			cin>>a[i][0]>>a[i][1]>>a[i][2];
		}
		int b[n+1];
		for(int i=2;i<=n;i++){
			b[i]=0;
		}
		b[1]=1;
		int t=0,k=0,ct=1;
		while(k<m){
			t++;
			for(int i=0;i<m;i++){
				if(a[i][0]==t){
					k++;
					if(b[a[i][1]]==1&&b[a[i][2]]==0){
						ct++;
						b[a[i][2]]=1;
					}
				}
			}
		}
		cout<<ct<<endl;
	}*/
	int n,m;
	while(cin>>n>>m){
		if(n==0&&m==0) break;
		int a[m][3],t,s,d;
		for(int i=0;i<m;i++){
			a[i][0]=0;
			a[i][1]=0;
			a[i][2]=0;
		}
		for(int i=0;i<m;i++){
			cin>>t>>s>>d;
			for(int j=i;j>=1;j--){
				if(a[j-1][0]>t){
					a[j][0]=a[j-1][0];
					a[j][1]=a[j-1][1];
					a[j][2]=a[j-1][2];
				}
				else if(a[j-1][0]<=t){
					a[j][0]=t;
					a[j][1]=s;
					a[j][2]=d;
					goto end;
				}
			}
			a[0][0]=t;
			a[0][1]=s;
			a[0][2]=d;
			end:;
		}
		int b[n+1];
		for(int i=2;i<=n;i++){
			b[i]=0;
		}
		b[1]=1;
		int ct=1;
		for(int i=0;i<m;i++){
			if(b[a[i][1]]==1&&b[a[i][2]]==0){
				ct++;
				b[a[i][2]]=1;
			}
		}
		cout<<ct<<endl;
	}
    return 0;
}