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>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
}

int main(){
	while(1){
		int n,m;
		cin>>n>>m;
		if(n==0) break;
		vip a(m);
		for(int i=0;i<m;i++) cin>>a[i].first>>a[i].second.first>>a[i].second.second;
		sort(a.begin(),a.end());
		vi b(n);
		b[0]=1;
		for(int i=0;i<m;i++){
			P p=a[i].second;
			int u=p.first-1,v=p.second-1;
			if(b[u]) b[v]=1;
		}
		int res=0;
		for(auto i:b) res+=i;
		cout<<res<<endl;
	}
}

C++: #include<iostream>
#include<algorithm>
#include<tuple>
using namespace std;

#define MAX_N 100000

tuple<int, int, int>X[MAX_N];
int n, m, a, b, c;
int V[MAX_N];

int main() {
	while (true) {
		for (int i = 0; i < MAX_N; i++) {
			X[i] = make_tuple(0, 0, 0);
			V[i] = 0;
		}
		V[1] = 1;
		cin >> n >> m;
		if (n == 0 && m == 0) {
			break;
		}
		for (int i = 0; i < m; i++) {
			cin >> a >> b >> c;
			X[i] = make_tuple(a, b, c);
		}
		sort(X, X + m);
		for (int i = 0; i < m; i++) {
			int a1 = get<0>(X[i]);
			int a2 = get<1>(X[i]);
			int a3 = get<2>(X[i]);
			if (V[a2] == 1) {
				V[a3] = 1;
			}
		}
		int sum = 0;
		for (int i = 0; i < MAX_N; i++) {
			sum += V[i];
		}
		cout << sum << endl;
	}
}

C++: #include<stdio.h>
#include<algorithm>
using namespace std;
pair<int,pair<int,int> > d[20000];
int e[20000];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<a;i++)e[i]=0;
		e[0]=1;
		for(int i=0;i<b;i++){
			int p,q,r;
			scanf("%d%d%d",&p,&q,&r);
			q--;
			r--;
			d[i]=make_pair(p,make_pair(q,r));
		}std::sort(d,d+b);
		for(int i=0;i<b;i++){
			if(e[d[i].second.first])e[d[i].second.second]=1;
		}
		int ret=0;
		for(int i=0;i<a;i++)ret+=e[i];
		printf("%d\n",ret);
	}
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> pii;

typedef pair<ll, pii> pipii;

int main() {
	int n, m;
	while(cin >> n >> m, n) {
		if(m == 0) {
			cout << 1 << endl;
			continue;
		}
		vector<pipii> v(m);
		rep(i, m) {
			cin >> v[i].first >> v[i].second.first >> v[i].second.second;
		}
		sort( v.begin(), v.end() );
		set<int> infe;
		infe.insert(1);
		rep(i, m) {
			pii p = v[i].second;
			if( infe.find(p.first) != infe.end() ) {
				infe.insert(p.second);
			}
		}
		cout << infe.size() << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct State{
	int t, s, d;
	State(int t_, int s_, int d_){
		t = t_; s = s_; d = d_;
	}
	State(){}
};
bool operator<(const State &a, const State &b){
	return a.t < b.t;
}

int main(){
	int N, M;
	while( cin >> N >> M, N || M ){
		vector<bool> c(N, false);
		c[0] = true;
		vector<State> v;
		for(int i=0 ; i < M ; i++ ){
			int t, s, d;
			cin >> t >> s >> d;
			s--, d--;
			v.push_back(State(t, s, d));
		}
		sort(v.begin(), v.end());
		for(int i=0 ; i < v.size() ; i++ ){
			if( c[v[i].s] ) c[v[i].d] = true;
		}
		int ans = 0;
		for(int i=0 ; i < N ; i++ ){
			if( c[i] ) ans++;
		}
		cout << ans << endl;
	}
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  while (cin >> n >> m, n) {
    vector<int> t(m), s(m), d(m);
    for (int i = 0; i < m; ++i) {
      cin >> t[i] >> s[i] >> d[i];
      --s[i], --d[i];
    }
    vector<int> idx(m);
    iota(begin(idx), end(idx), 0);
    sort(begin(idx), end(idx), [&](int i, int j) {
      return t[i] < t[j];
    });
    vector<int> infected(n);
    infected[0] = 1;
    for (int i : idx) {
      if (infected[s[i]]) {
        infected[d[i]] = 1;
      }
    }
    int res = accumulate(begin(infected), end(infected), 0);
    cout << res << '\n';
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
int main(void){
    int n,m;
    while(cin>>n>>m,n){
        map<int,pii> mp;
        vi infect(20001,0);
        infect[1]=1;
        rep(i,m){
            int t,s,d;
            cin>>t>>s>>d;
            mp[t]=make_pair(s,d);
        }
        for(auto p:mp){
            infect[p.sc.sc]=infect[p.sc.sc] | infect[p.sc.fs];
        }
        cout<<accumulate(all(infect),0)<<endl;
    }
}