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 <vector>
#include <algorithm>
#include <cstring>

using namespace std;

int main(){
	int n, m;
	bool infect[20001];
	pair< int,pair<int,int> > packet[20000];
	while(cin >> n >> m, n){
		memset(infect, false, sizeof(infect));
		infect[1] = true;
		for(int i=0;i<m;i++){
			int t, s, d;
			scanf("%d %d %d", &t, &s, &d);
			packet[i] = make_pair(t,make_pair(s,d));
		}
		sort(packet,packet+m);
		for(int i=0;i<m;i++){
			int s = packet[i].second.first;
			int d = packet[i].second.second;
			if(infect[s]) infect[d] = true;
		}
		int ans = 0;
		for(int i=1;i<=n;i++) ans += infect[i];
		cout << ans << endl;
	}
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;
int inf = 1000000000;

int main(void) {
  int n, m;
  while( cin >> n >> m ){
    if( n == 0 && m == 0 ) break;
    vector<bool> v(n+1, false);
    v[1] = true;
    vector< vector<int> > d(m, vector<int>(3));
    for(int i=0; i<m; i++){
      for(int j=0; j<3; j++) cin >> d[i][j];
    }
    sort(d.begin(), d.end());
    for(int i=0; i<m; i++){
      if( v[ d[i][1] ] ) v[ d[i][2] ] = true;
    }
    int cnt = 0;
    for(int i=0; i<=n; i++) cnt += v[i];
    cout << cnt << endl;
  }

  return 0;
}

// EOF

C++: #include <iostream>
#include <cstring>
#include <algorithm>
#include <utility>
#include <vector>
using namespace std;

vector<pair<int, pair<int , int> > > l;

int v[20010];
int n, m, ans;


int main(void){
	int i;
	pair<int, pair<int, int> > p;
	while( cin >> n >> m, n){
		ans = 0;
		memset(l, 0, sizeof(l));
		memset(v, 0, sizeof(v));
		for(i = 0; i < m; i++){
			cin >> p.first >> p.second.first >> p.second.second;
			l.push_back(p);
		}
		sort(l.begin(), l.end());
		v[1] = 1;
		for(i = 0; i < m; i++) if(v[l[i].second.first]) v[l[i].second.second] = 1;
		for(i = 1; i <= n; i++) if(v[i]) ans++;
		cout << ans << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
typedef pair<int,int> P;

//-----------------------------------------------------------------------

const int SZ=20005;
bool isInfected[SZ];
pair<int,P> p[SZ];

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n,m;
    while(cin>>n>>m,n)
    {
	REP(i,n) isInfected[i]=false;
	isInfected[0]=true;

	REP(i,m){
	    int t,s,d;
	    cin>>t>>s>>d;
	    s--; d--;
	    p[i]=make_pair(t,P(s,d));
	}
	sort(p,p+m);

	REP(i,m){
	    int s=p[i].second.first;
	    int d=p[i].second.second;
	    if(isInfected[s]) isInfected[d]=true;
	}
	
	int ans=0;
	REP(i,n) if(isInfected[i]) ans++;
	cout<<ans<<endl;
    }
}

C++: # define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
//# define M_PI 3.141592
# define INF ((int)(1<<30))
# define FOR(i,n) for(int i=0;i<(int)n;i++)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define toRad 2.0*M_PI/360.0
# define inin(x) int x;cin>>x;
# define all(x) x.begin(),x.end()
# define debug(x) cout<<#x<<" :"<<x<<endl;
# define rep(i,n) for(int i=0;i<(int)n;i++)
# define EPS 1e-12
# define CHECK(i,a) FOR(i,a.size())cout<<#a<<"["<<i<<"] : "<<a[i]<<endl; 
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
int dx[4] = { 0,-1,1,0 }, dy[4] = { 1,0,0,-1 };

int a[21000];
int main()
{
	int n, m;
	while (cin >> n >> m&&n)
	{
		memset(a, 0, sizeof a);
		a[1] = 1;
		vector<piii> v;
		FOR(i, m)
		{
			piii x;
			cin >> x.first >> x.second.first >> x.second.second;
			v.push_back(x);
		}
		sort(all(v));
		FOR(i, m)
		{
			a[v[i].second.second] += a[v[i].second.first];
		}
		int ans = 0;
		FOR(i, n + 1)if (a[i])ans++;
		cout << ans << endl;
	}
}

C++: #include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	long long n,m;
	while(cin>>n>>m,n){
		long long a[20001]={0},b[20001][2]={0},t,s=0;
		a[1]=1;
		r(i,m){
			cin>>t;
			cin>>b[t][0]>>b[t][1];
		}
		r(i,20001)if(a[b[i][0]])a[b[i][1]]=1;
		r(i,20001)if(a[i])s++;
		cout<<s<<endl;
	}
}

C++: #include <bits/stdc++.h>
#define ll long long
#define p pair<ll, int>
using namespace std;

int inf[20005];
int main() {
    int n, m;
    while (cin >> n >> m, n | m) {
        memset(inf, 0, sizeof(inf));
        inf[1] = 1;
        vector<p> v;
        int s[m], d[m];
        for (int i = 0; i < m; i++) {
            ll t;
            cin >> t >> s[i] >> d[i];
            v.push_back(p(t, i));
        }
        sort(v.begin(), v.end());
        for (int i = 0; i < m; i++) {
            int idx = v[i].second;
            if (inf[s[idx]]) inf[d[idx]] = 1;
        }
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            if (inf[i]) ans++;
        }
        cout << ans << endl;
    }
    return 0;
}