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 <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y) (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)
#define dump3(x, y, z) (cout << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", "<< z << ")" << endl)

typedef long long ll;
typedef pair<int, int> pii;

int N, M;

#define MAX 20001
vector<int> connect[MAX];
bool visit[MAX];

vector<int> path;

void topological_sort(int i)
{
	if (!visit[i]) {
		visit[i] = true;
		rep(j, N)
			if (find(ALL(connect[i]), j) != connect[i].end())
				topological_sort(j);
		path.push_back(i);
	}
}

int main(void)
{
	while (cin >> N >> M, N|M) {
		fill(connect, connect+N, vector<int>());
		fill(visit, visit+N, false);

		rep(i, M) {
			int t, s, d;
			cin >> t >> s >> d;

			s--, d--;
			connect[s].push_back(d);
		}

		path = vector<int>();
		rep(i, N)
			topological_sort(i);

		cout << path[0]+1 << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
struct P {
	long long time, from, to;
};
bool operator<(P a, P b) { return a.time < b.time; }
bool operator>(P a, P b) { return a.time > b.time; }
bool a[20001];
int main() {
	int n, m;
	while (cin >> n >> m&&n != 0 && m != 0) {
		for (int i = 1; i <= n; i++) a[i] = false;
		a[1] = true;
		priority_queue<P, vector<P>, greater<P>>p;
		for (int i = 0; i < m; i++) {
			int t, s, d;
			cin >> t >> s >> d;
			p.push(P{ t,s,d });
		}
		int sum = 1;
		while (!p.empty()) {
			P t = p.top(); p.pop();
			if (a[t.from]) {
				if (!a[t.to]) sum++;
				a[t.to] = true;
			}
		}
		cout << sum << endl;
	}
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <tuple>

using namespace std;
using ll = long long;


int main()
{
    while (true) {
        int N, M;
        cin >> N >> M;
        if (N == 0 and M == 0) {
            break;
        }
        vector<int> ng(N, 0);
        ng[0] = 1;
        vector<tuple<int, int, int>> pac;
        for (int i = 0; i < M; i++) {
            int t, s, d;
            cin >> t >> s >> d;
            s--, d--;
            pac.push_back(make_tuple(t, s, d));
        }
        sort(pac.begin(), pac.end());
        for (const auto& p : pac) {
            const int from = get<1>(p);
            const int to = get<2>(p);
            if (ng[from]) {
                ng[to] = 1;
            }
        }
        cout << accumulate(ng.begin(), ng.end(), 0) << endl;
    }
    return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;

struct Edge{int to,from,cost;};

#define debug cout

template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repn(i,m,n) for(int i=(m);i<=(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;--i)
#define repnd(i,m,n) for(int i=(n);i>=(m);--i)
#define rep0(i,n) for(i=0;i<(n);++i)
#define repn0(i,m,n) for(i=(m);i<=(n);++i)
#define repd0(i,n) for(i=(n)-1;i>=0;--i)
#define repnd0(i,m,n) for(i=(n);i>=(m);--i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define SS stringstream
#define X second
#define Y first
#define PUTLINE debug<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

const int dx[]={1,-1,0,0,1,-1,1,-1,0};
const int dy[]={0,0,1,-1,1,-1,-1,1,0};

int n,m,t;
vector<pair<int,pint> > p;
int v[20010];

int main() {
	IL{
		cin>>n>>m;
		if(n==0&&m==0)break;
		p.clear();
		rep(i,m){
			int t,s,d;
			cin>>t>>s>>d;
			p.PB(MP(t,MP(s,d)));
		}
		sort(all(p));
		memset(v,0,sizeof(v));
		v[1]=1;
		rep(i,m){
			if(v[p[i].second.first]==1)v[p[i].second.second]=1;
		}
		int res=0;
		repn(i,1,n)res+=v[i];
		cout<<res<<endl;
	}
	
	return 0;
}