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 <bits/stdc++.h>

using namespace std;

int main(){
    bool c[20010];
    int n, m;
    while(cin >> n >> m, n+m){
        fill(c, c+20010, false);
        c[1] = true;
        vector<pair<int, pair<int, int>>> p;
        for(int i=0; i < m; i++){
            int t, s, d;
            cin >> t >> s >> d;
            p.push_back(make_pair(t, make_pair(s, d)));
        }
        sort(p.begin(), p.end());
        for(int i=0; i < m; i++){
            if(c[p[i].second.first]){c[p[i].second.second] = true;}
        }
        int ret = 0;
        for(int i=0; i <= n; i++) if(c[i]) ret++;
        cout << ret << endl;
    }
}

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 <functional>
#include <algorithm>
#include <vector>
using namespace std;

struct D {
    int t, s ,d;
    bool operator <(const D& rhs) {
        return t < rhs.t;
    }
};

int main(void){
    int n, m;
    int _t, _s, _d;
    vector<D> data;
    D _data;
    bool f[20202];
    
    while (1) {
        cin >> n >> m;
        if (!n && !m) break;
        data.clear();
        for (int i = 0; i < n; i++) f[i] = false;
        f[0] = true;
        
        for (int i = 0; i < m; i++) {
            cin >> _t >> _s >> _d;
            _s--; _d--;
            _data.t = _t;
            _data.s = _s;
            _data.d = _d;
            data.push_back(_data);
        }
        sort(data.begin(), data.end());
        
        for (int i = 0; i < m; i++) {
            if (f[data[i].s] == true) f[data[i].d] = true;
            //printf("data[i].s=%d data[i].d=%d i=%d\n",data[i].s,data[i].d,i);
        }
        int ans = 0;
        for (int i = 0; i < n; i++) if (f[i] == true) ans++;
        cout << ans << endl;
    }
    return 0;
}

C++: #include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e8;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

typedef struct Data {
  int tm, src, dst;
  bool operator<(const Data &o) const { return tm < o.tm; }
} data;

signed main() {
  int n, m;
  while (cin >> n >> m) {
    if (n == 0 && m == 0) break;
    set<int> virus;
    virus.insert(1);
    vector<data> d(m);
    rep(i, m) cin >> d[i].tm >> d[i].src >> d[i].dst;
    sort(all(d));
    rep(i, m) {
      if (virus.count(d[i].src)) {
        virus.insert(d[i].dst);
      }
    }
    cout << virus.size() << endl;
  }

  return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct data{
	int t,s,d;
	bool operator <(const data& d1)const{
		return t<d1.t;
	}
};

int n,m;
data dat[20001];
bool flag[20001];
int cnt;
int main(void){
	while(1){
		scanf("%d %d",&n,&m);
		if(n+m==0)break;
		memset(flag,false,sizeof(flag));
		flag[1]=true;
		cnt=1;
		for(int i=0;i<m;i++){
			scanf("%d %d %d",&dat[i].t,&dat[i].s,&dat[i].d);
		}
		sort(dat,dat+m);
		for(int i=0;i<m;i++){
			if(flag[dat[i].s] && !flag[dat[i].d]){
				flag[dat[i].d]=true;
				cnt++;
			}
		}
		printf("%d\n",cnt);
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
typedef pair<int,int> P;
typedef pair<int,P> PP;
bool infected[20000];
vector<PP> vc;
int main(){
	while(true){
		int N,M;
		cin>>N>>M;
		if(N==0) break;
		rep(i,N) infected[i]=0;
		infected[0]=true;
		int cnt=0;
		vc.clear();
		rep(i,M){
			int t,s,d;
			cin>>t>>s>>d;
			vc.pb(PP(t,P(s-1,d-1)));
		}
		sort(all(vc));
		rep(i,M){
			int s=vc[i].sc.fs,t=vc[i].sc.sc;
			if(infected[s]) infected[t]=true;
		}
		rep(i,N) if(infected[i]) cnt++;
		cout<<cnt<<endl;
	}
}

C++: #include<cstdio>
#include<algorithm>
using namespace std;
#define MAX  20000

class Message{
    public:
    int t, s, d;
    Message(){}
    bool operator < ( const Message &m ) const{
	return t < m.t;
    }
};

int N, M;
bool infected[MAX];
Message messages[MAX];

main(){
    while(1){
	scanf("%d %d", &N, &M);
	if ( N == 0 && M == 0 ) break;
	for ( int i = 0; i < M; i++ ){
	    scanf("%d %d %d", &messages[i].t, &messages[i].s, &messages[i].d);
	}

	sort( messages, messages + M );
	for ( int i = 0; i < N; i++ ) infected[i] = false;

	infected[0] = true;

	for ( int i = 0; i < M; i++ ){
	    int s = messages[i].s - 1;
	    int d = messages[i].d - 1;
	    if ( infected[s] ) infected[d] = true;
	}

	int sum = 0;
	for ( int i = 0; i < N; i++ ) if ( infected[i] ) sum++;
	printf("%d\n", sum);
    }
}