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;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999

int main(){
    int n,m;
    while(cin>>n>>m&&(n||m)){
        vector<pair<int,pii>> data;
        rep(i,m){
            int t,s,d;
            cin>>t>>s>>d;
            data.pb(make_pair(t,pii(s,d)));
        }
        sort(all(data));
        
        
        bool infected[20010];
        rep(i,20010)infected[i]=false;
        infected[1]=true;
        rep(i,data.size()){
            pii p = data[i].second;
            int s = p.first,t=p.second;
            if(infected[s]){
                infected[t]=true;
            }
        }
        int sum=0;
        rep(i,20010){
            if(infected[i])sum++;
        }
        cout<<sum<<endl;
    }
}

C++: #include <iostream>

#define INF 1000000010

using namespace std;

void swap(int *a,int *b){
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

int main(){
	int n,m;

	while(cin>>n>>m){
		if(n==0 && m==0)break;

		int *t,*state;
		int *s,*d;

		t = new int[m];
		state = new int[n+1];
		s = new int[m];
		d = new int[m];

	
		for(int i=0;i<m;i++){
			t[i]=INF;
			s[i]=0;
			d[i]=0;
		}
		for(int i=0;i<=n;i++){
			state[i]=0;
		}
		state[1]=1;

		for(int i=0;i<m;i++){
			cin>>t[i]>>s[i]>>d[i];
		}

		for(int i=0;i<m;i++){
			for(int j=m-1;j>i;j--){
				if(t[j]<=t[j-1]){
					swap(&t[j],&t[j-1]);
					swap(&s[j],&s[j-1]);
					swap(&d[j],&d[j-1]);
				}
			}
		}

		/*
		for(int i=0;i<m;i++){
			cout<<t[i]<<" "<<s[i]<<" "<<d[i]<<endl;
		}
		*/


		for(int i=0;i<m;i++){
			if(state[s[i]]==0)continue;

			state[d[i]]=1;
		}

		int ans=0;
		for(int i=1;i<=n;i++){
			if(state[i]==1){
				ans++;
			}
		}

		cout<<ans<<endl;


	}
	return 0;
}

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

const int INF = 1e+9;
typedef pair<int, int> P;
typedef pair<int, P> pp;

int N, M;
vector<pp> data;

int main() {
	while(cin >> N >> M && (N || M)){
		int t, s, d;
		bool check[20010] = {0};
		for(int i = 0; i < M; ++i){
			scanf("%d%d%d", &t, &s, &d);
			data.push_back(pp(t, P(s, d)));
		}
		sort(data.begin(), data.end());
		check[1] = true;
		for(int i = 0; i < M; ++i){
			if(check[data[i].second.first])
				check[data[i].second.second] = true;
		}
		int cnt = 0;
		for(int i = 1; i <= N; ++i){
			if(check[i])
				cnt++;
		}
		cout << cnt << endl;
		data.clear();
	}
	return 0;
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	int N, M;
	while(cin >> N >> M, N) {
		vvi data(M, vi(3));
		REP(i, M) {
			REP(j, 3) {
				cin >> data[i][j];
			}
		}
		sort(ALL(data));

		vi infected(N);
		infected[0] = 1;
		REP(i, M) {
			if(infected[data[i][1]-1]) {
				infected[data[i][2]-1] = 1;
			}
		}

		int ans = 0;
		REP(i, N) {
			ans += infected[i];
		}


		cout << ans << endl;
	}

	return 0;
}

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>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n, m;
    while(1){
        cin >> n >> m;
        if(n + m == 0) break;
        vector<pair<int, pair<int, int> > > data;
        rep(i, 0, m){
            int t, s, d;
            cin >> t >> s >> d; 
            data. push_back(make_pair(t, make_pair(s, d)));
        } 
        sort(all(data));
        set<int> st;
        st.insert(1);
        rep(i, 0, m){
            if(st.count(data[i]. second. first)){
                st.insert(data[i]. second. second);
            }
        }
        cout << st.size() << endl;
    }
}