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 <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

struct Data {
	ll t, s, d;
	Data(ll _t, ll _s, ll _d) :t(_t), s(_s), d(_d) {}
	bool operator<(const Data& e) {
		return t < e.t;
	}
};
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	int kkt = 89;
	while (kkt) {
		int n, m; scanf("%d %d", &n, &m); if (n == 0 && m == 0) break;
		vector<Data> vd;
		for (int i = 0; i < m; i++) {
			ll x, y, z; scanf("%lld %lld %lld", &x, &y, &z);
			y--; z--;
			vd.emplace_back(x, y, z);
		}
		sort(vd.begin(), vd.end());
		vector<bool> vir(n, false);
		vir[0] = true;
		for (int i = 0; i < m; i++) {
			if (!vir[vd[i].s]) continue;
			vir[vd[i].d] = true;
		}
		int res = 0; for (int i = 0; i < n; i++) if (vir[i]) res++;
		printf("%d\n", res);
	}
	return 0;

}

C++: #include <iostream>
#include <vector>
#include <bitset>
#include <cstring>
#include <queue>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	while(1){
		int n,m; cin >> n >> m;
		if(n==0&&m==0)break;
		vector<pair<int,pair<int,int>>> v(m);
		for(int i=0;i<m;i++){
			cin >> v[i].first >> v[i].second.first >> v[i].second.second;
		}
		sort(v.begin(),v.end());
		int ans=1;
		vector<bool> a(n+1);
		a[1]=1;
		for(int i=0;i<m;i++){
			if(a[v[i].second.first]){
				if(!a[v[i].second.second]){
					a[v[i].second.second]=1;
					ans++;
				}
			}
		}
		cout << ans << endl;
	}
}

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

using namespace std;

#define all(c) (c).begin(), (c).end()

int N, M;

int solve(vector<tuple<int, int, int> >& record){
    sort(all(record));
    vector<int> infected(N); infected[0] = 1;
    for(auto x: record){
        int src, dst;
        tie(ignore, src, dst) = x;
        infected[dst] |= infected[src];
    }
    return count(all(infected), 1);
}

int main(){
    while(cin >> N >> M, N|M){
        vector<tuple<int, int, int> > record;
        record.reserve(M);
        while(M--){
            int t, s, d;
            cin >> t >> s >> d;
            s--; d--;
            record.emplace_back(t, s, d);
        }
        cout << solve(record) << '\n';
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,m,t,s,d;
    while (cin>>n>>m) {
        if (n==0&&m==0) {
            break;
        } else {
            std::vector<tuple<int,int,int>> vec;
            for (int i=0;i<m;i++) {
                cin>>t>>s>>d;
                vec.emplace_back(t,s,d);
            }
            sort(vec.begin(),vec.end());
            std::deque<int> pc(n+1,0);
            pc[1]=1;
            for (int j=0;j<m;j++) {
                int& source=get<1>(vec[j]);
                int& dst=get<2>(vec[j]);
                if (pc[source]==1) {
                    pc[dst]=1;
                }
            }
            int count=0;
            for (int k=1;k<=n;k++) {
                if (pc[k]==1) {
                    count++;
                }
            }
            cout<<count<<endl;
        }
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;
using P = pair<int, int>;
using namespace std;

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

struct edge {
    int from, to, cost;
    edge(int f, int t, int c) :from(f), to(t), cost(c) {}
};

bitset<200001> ans;

int main() {
    int n, m;
    while (cin >> n >> m and n) {
        ans.reset();
        vector< pair<int, pair<int, int>> > p;
        rep(i, m) {
            int t, s, d;
            cin >> t >> s >> d;
            s--;
            d--;
            p.push_back(make_pair(t, make_pair(s, d)));
        }
        sort(p.begin(), p.end());
        vector<edge> g[20001];
        ans[0] = 1;
        rep(i, m) {
            pair<int, int> tmp = p[i].second;
            int to = tmp.first, from = tmp.second;
            if (ans[to]) ans[from] = 1;
        }
        cout << ans.count() << endl;
    }
    return 0;
}