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<utility>
using namespace std;

typedef pair<int,int> P;
typedef pair<int,P> P2;

int main(){
	int n,m,t,s,d;
	P2 p[20010];
	bool v[20010];
	
	while(cin >> n >> m && (n||m)){
		for(int i=1;i<=n;i++)v[i] = false;
		v[1] = true;
		
		for(int i=0;i<m;i++){
			cin >> t >> s >> d;
			p[i] = P2(t,P(s,d));
		}
		
		sort(p,p+m);
		
		for(int i=0;i<m;i++){
			P infe = p[i].second;
			if(v[infe.first])v[infe.second] = true;
		}
		
		int ans = 0;
		for(int i=1;i<=n;i++)
			if(v[i])ans++;
		cout << ans << endl;
	}
}

C++: #include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()
const int INF = 1e9;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PII;

/* struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
}; */


/** Problem2155 : Infected Computer **/
struct E {
	int t, s, d;
	E(int t_, int s_, int d_):t(t_), s(s_), d(d_){}
	E(){}
};

bool cmp(const E &a, const E &b)
{
	return a.t < b.t;
}

const int MAX = 20000;

int main()
{
	int N, M;
	while (cin>>N>>M, N||M) {
		set<int> infected;
		vector<E> ls(M);
		
		infected.insert(0);
		
		rep(i, M) {
			cin>>ls[i].t>>ls[i].s>>ls[i].d;
			ls[i].s--, ls[i].d--;
		}
		sort(ALL(ls), cmp);
		
		int now = -1;
		vector<int> tmp;
		rep(i, M) {
			if (now != ls[i].t) {
				rep(j, tmp.size()) infected.insert(tmp[j]);
				tmp.clear();
				now = ls[i].t;
			}
			
			if (infected.count(ls[i].s)) {
				tmp.push_back(ls[i].d);
			}
		}
		rep(j, tmp.size()) infected.insert(tmp[j]);
		
		cout << infected.size() << endl;
	}
}

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

using namespace std;

#define for_(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
#define makep make_pair

int N, M;
int t[20020], s[20020], d[20020];

int v[20020];
vector<piii> pac;

void solve() {
	pac.clear();
	for_(i,0,M) pac.push_back(piii(t[i], pii(s[i], d[i])));
	sort(all(pac));
	
	memset(v, 0, sizeof(v));
	v[1] = 1;
	for_(i,0,M) {
		piii pp = pac[i];
		pii p = pp.second;
		v[p.second] |= v[p.first];
	}
	
	int ans = 0;
	for_(i,1,N + 1) ans += v[i];
	cout << ans << endl;
}

int main() {
	while (cin >> N >> M, N) {
		for_(i,0,M) cin >> t[i] >> s[i] >> d[i];
		solve();		
	}
	
	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];
P p[20000];
int main() {
	long long n, m;
	while (cin >> n >> m&&n != 0 && m != 0) {
		for (long long i = 1; i <= n; i++) a[i] = false;
		a[1] = true;
		for (long long i = 0; i < m; i++) {
			cin >> p[i].time >> p[i].from >> p[i].to;
		}
		sort(p, p + m);
		long long sum = 1;
		for (int i = 0; i < m; i++) {
			if (a[p[i].from]) {
				if (!a[p[i].to]) sum++;
				a[p[i].to] = true;
			}
		}
		cout << sum << endl;
	}
}

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 20010
int dp[MAX];

class node{
public:
	int t, s, d;
	node(int t, int s, int d):t(t), s(s), d(d){}

	bool operator<(const node& r) const{
		return t < r.t;
	}
};

int main(void)
{
	while (cin >> N >> M, N|M) {
		vector<node> ns;
		rep(i, M) {
			int t, s, d;
			cin >> t >> s >> d;
			ns.push_back(node(t, --s, --d));
		}
		sort(ALL(ns));

		memset(dp, 0, sizeof(dp));
		dp[0] = 1;
		rep(i, ns.size())
			dp[ns[i].d] |= dp[ns[i].s];

		int ans = 0;
		rep(i, N)
			ans += dp[i];
		cout << ans << endl;
	}
	return 0;
}