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<algorithm>
#include<map>
using namespace std;
#define MAX 20000
typedef pair < int , int > Pi;
typedef pair < int , Pi > Pii;
#define fr first
#define sc second
int main(){
  int n, m;
  Pii tsm[MAX];
  while(cin >> n >> m , n){
    for(int i = 0 ; i < m ; i++ ){
      cin >> tsm[i].fr >> tsm[i].sc.fr >> tsm[i].sc.sc;
      tsm[i].sc.fr--,tsm[i].sc.sc--;
    }
    sort( tsm, tsm + m);
    bool c[MAX] = {};
    c[0] = true;
    int ret = 1;
    for(int i = 0 ; i < m ; i++ ){
      if(c[tsm[i].sc.fr] && !c[tsm[i].sc.sc]++) ret++;
    }
    cout << ret << endl;
  }
}

C++: #include <iostream>
using namespace std;
struct set{
  int t;
  int s;
  int d;
};
int main(){
  int n,m,i,j,cnt,source,destination,start,end[20001],flag;
  struct set data[20001];
  while(1){
    for(i=1;i<20001;i++) end[i]=0;
    end[1]=1;
    cin >> n >> m;
    if(n==0&&m==0) break;
    for(i=0;i<m;i++){
      cin >> data[i].t >> data[i].s >> data[i].d;
    }
    for(i=0;i<m;i++){
      for(j=1;j<m;j++){
	if(data[i].t<data[i-1].t) swap(data[i],data[i-1]);
      }
    }
    for(i=0;i<m;i++){
      if(end[data[i].s]==1) end[data[i].d]=1;
    }
    cnt=0;
    for(i=1;i<=n;i++) if(end[i]==1) cnt++;
    cout << cnt << endl;
      
    /*      for(i=0;i<m;i++){
	cout << data[i].t << ' ' << data[i].s << ' ' << data[i].d << endl;
	}
      for(i=0;i<m;i++){
	if(data[i].s==1||data[i].d==1){
	  source=data[i].s;
	  destination=data[i].d;
	  start=i+1;
	  flag=1;
	  break;
	}
      }
      if(flag==1){
	if(source==1){
	  end[data[i].d]=1;
	  cnt=2;
	}
	if(destination==1) cnt=1;
	for(i=start;i<m;i++){
	  if(end[data[i].s]==1&&end[data[i].d]==0){
	    cnt++;
	    end[data[i].d]=1;
	  }
	}
	cnt=0;
        for(i=1;i<=n;i++){
	  if(end[i]==1) cnt++;
	}
	cout << cnt << endl;
      }
      else cout << 1 << endl;
    }
    else cout << 1 << endl;
  }
      */
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;main(){for(int N,M,i;cin>>N>>M,N;cout<<N<<endl){vector<int>v(N+1),s(M+1),d(M+1);for(i=0;i++<M;cin>>s[N]>>d[N])cin>>N;v[1]=N=1;for(i=0;i++<M;)if(v[s[i]])v[d[i]]=1&&!v[d[i]]&&N++;}}

C++: #include <iostream>
#include <algorithm>
#include <cstring>

#define MAX_N 20001
#define MAX_M 20001

using namespace std;

struct datum {
    int t, s, d;
    datum(int t=0, int s=0, int d=0) : t(t), s(s), d(d) {}
    bool operator<(const datum &o) const {
        return t < o.t;
    }
};

int N, M;
bool infected[MAX_N];
datum data[MAX_M];

bool init() {
    cin >> N >> M;
    if (N == 0 && M == 0) return false;
    memset(infected, 0, sizeof(infected));
    infected[1] = true;
    for (int i = 0; i < M; i++) 
        cin >> data[i].t >> data[i].s >> data[i].d;
    sort(data, data+M);
    return true;
}

int main() {
    while (init()) {
        for (int i = 0; i < M; i++) 
            if (infected[data[i].s]) 
                infected[data[i].d] = true;
        int cnt = 0;
        for (int i = 1; i <= N; i++)
            if (infected[i]) cnt++;
        cout << cnt << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int main()
{
	for(int n,m;cin>>n>>m,n|m;){
		vector<int> ts(m),ss(m),ds(m);
		for(int i=0;i<m;i++){
			cin>>ts[i]>>ss[i]>>ds[i];
			ss[i]--,ds[i]--;
		}
		
		map<int,int> ma;
		for(int i=0;i<m;i++)
			ma[ts[i]]=i;
		
		vector<int> flg(n);
		fill(begin(flg),end(flg),false);
		flg[0]=1;
		map<int,int>::iterator it=ma.begin();
		for(int i=0;i<m;i++,it++){
			int j=it->second;
			flg[ds[j]]|=flg[ss[j]];
		}
		
		cout<<count(begin(flg),end(flg),true)<<endl;
	}
	
	return 0;
}

C++: #include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int N,M;
vector<int> G[20004];
bool f[20004];

void dfs(int v) {
    rep(i,G[v].size()) {
        int e = G[v][i];
        if(!f[e]) {
            dfs(e);
            f[e]=true;
        }
    }

}
void solve() {
    rep(i,20004) G[i].clear();
    rep(i,20004) f[i]=false;

    rep(i,M) {
        int t,s,d;
        cin>>t>>s>>d;
        G[s].pb(d);
    }
    dfs(1);
    f[1]=true;

    int ans=0;
    rep(i,20004) if(f[i]) ans++;
    cout<<ans<<endl;

}

int main() {
    while(cin>>N>>M) {
        if(N+M==0) break;
        solve();
    }
    return 0;
}