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 <stdio.h>
#include <stdlib.h>
#include <string.h>

struct P{
	int t;
	int s;
	int d;
};

int cmp(const void *a,const void *b){
	struct P *tmp1 = (struct P *)a;
	struct P *tmp2 = (struct P *)b;
	return tmp1->t - tmp2->t;
}

int main(void){
	int n, m, count, i, p[20000];
	struct P data[20000];
	while(1){
		scanf("%d%d",&n,&m);
		if(n == 0 && m == 0)
			break;
		memset(p,0,sizeof(p));
		p[0] = 1;
		for(i = 0;i < m;i++)
			scanf("%d%d%d",&data[i].t,&data[i].s,&data[i].d);
		qsort(data,m,sizeof(data[0]),cmp);
		for(i = 0;i < m;i++){
			if(p[data[i].s - 1])
				p[data[i].d - 1] = 1;
		}
		count = 0;
		for(i = 0;i < n;i++)
			if(p[i]) count++;
		printf("%d\n",count);
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<functional>
#include<map>
#define p pair<int,int>
#define P pair<int,p>
using namespace std;

bool c[20000];
int main() {
	int a, b;
	while (cin >> a >> b, a | b) {
		memset(c, false, sizeof(c));
		c[0] = true;
		P d[20000];
		for (int e = 0; e < b; e++) {
			int f, g, h; scanf("%d%d%d", &f, &g, &h); g--; h--;
			d[e] = P(f, p(g, h));
		}
		sort(d, d + b);
		for (int e = 0; e < b; e++) {
			if (c[d[e].second.first]) {
				c[d[e].second.second] = true;
			}
		}
		int e = 0;
		for (bool f : c) {
			if (f)e++;
		}
		cout << e << endl;
	}
}

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

int main(){
  int n,m,i,t,s,d;
  for(;cin>>n>>m,n;){
    vector<pair<int,pair<int,int> > >V;
    set<int> S;
    S.insert(1);
    for(i=0;i<m;i++){
      cin>>t>>s>>d;
      V.push_back(make_pair(t,make_pair(s,d)));
    }
    sort(V.begin(),V.end());
    for(i=0;i<m;i++)
      if(S.find(V[i].second.first)!=S.end())
        S.insert(V[i].second.second);
    cout<<S.size()<<endl;
  }
}

C++: #include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

signed main(void)
{
  while(true) {
    int n, m;
    cin >> n >> m;
    if(!n && !m) break;
    VVI rec;
    REP(i, m) {
      int a, b, c;
      cin >> a >> b >> c;
      rec.PB({a, b-1, c-1});
    }
    sort(ALL(rec));
    /*REP(i, m) {
      REP(j, 3) {
        cout << rec[i][j] << " ";
      }
      cout << endl;
    }*/
    bool g[20010] = {false};
    g[0] = true;
    REP(i, m) {
      if(g[rec[i][1]]) g[rec[i][2]] = true;
    }
    int ret = 0;
    REP(i, n) if(g[i]) ret++;
    cout << ret << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

struct A{
	int t,s,d;
	A(int t,int s,int d):t(t),s(s),d(d){}
	bool operator<(const A &a)const{return t<a.t;}
};

bool infected[20000];
int main(){
	int n,m;
	while(cin>>n>>m,n||m){
		vector<A> v;
		v.reserve(m);
		memset(infected,false,sizeof(infected));
		infected[0]=true;
		rep(i,m){
			int t,s,d;
			cin>>t>>s>>d;
			v.push_back(A(t,s-1,d-1));
		}
		sort(v.begin(),v.end());
		rep(i,v.size()){
			infected[v[i].d] |= infected[v[i].s];
		}
		cout<<count(infected,infected+n,true)<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>

#define rep(i, n) for(int i = 0; i < n; i++)

typedef long long ll;
using namespace std;
int mod = 1000000007;

bool infected[20001];

void init(){
    rep(i, 20001) infected[i] = false;
    infected[1] = true;
}

int main(void){
    int N, M;
    vector<int> ans;
    while(true){
        init();
        cin >> N >> M;
        if(N == 0) break;
        vector<pair<int, pair<int, int>>> pack(M);
        rep(i, M){
            int t, s, d; cin >> t >> s >> d;
            pack[i] = make_pair(t, make_pair(s, d));
        }
        sort(pack.begin(), pack.end());
        rep(i, M){
            if(infected[pack[i].second.first]) infected[pack[i].second.second] = true;
        }
        int cnt = 0;
        rep(i, N+1) if(infected[i]) cnt++;
        ans.push_back(cnt);
    }
    rep(i, ans.size()) cout << ans[i] << endl;
    return 0;
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
class packet {
public:
	int t, s, d;
	bool operator<(const packet &other) {
		return this->t < other.t;
	}
};
signed main() {
	int n, m;
	while (cin >> n >> m, n||m) {
		vector<bool>v(n, false); v[0] = true;
		vector<packet>p(m);
		rep(i, 0, m) {
			cin >> p[i].t >> p[i].s >> p[i].d;
			p[i].s--; p[i].d--;
		}
		sort(p.begin(), p.end());
		rep(i, 0, m) {
			if (v[p[i].s] == true)v[p[i].d] = true;
		}
		cout << accumulate(v.begin(), v.end(), 0) << endl;
	}
	return 0;
}