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;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)

int n,m;
vector<tuple<int,int,int>> dat;

int solve(){
    sort(dat.begin(), dat.end());
    vector<int> infected(n+1);
    infected[1] = true;
    for(auto &e : dat){
        infected[get<2>(e)] |= infected[get<1>(e)];
    }
    return count(infected.begin(), infected.end(), true);
}

int main(){
    while(cin >> n >> m && n){
        dat.resize(m);
        rep(i,m){
            int t,s,d;
            cin >> t >> s >> d;
            dat[i] = tie(t,s,d);
        }
        cout << solve() << endl;
    }
}

C++: #include <cstdio>
#include <vector>
using namespace std;
struct dts{
    int t;
    int s;
    int d;
};

int main(void){
    int N,M,i,cnt;
    while(1){
        scanf("%d",&N);
        scanf("%d",&M);
        if(!N && !M){break;}
        int pcs[N];
        vector<dts> datas;
        for(i=0;i<N;i++){pcs[i]=0;}
        pcs[0]=1;
        cnt=0;
        for(i=0;i<M;i++){
            struct dts buf;
            scanf("%d",&buf.t);
            scanf("%d",&buf.s);
            scanf("%d",&buf.d);
            datas.push_back(buf);
        }
        sort(datas.begin(),datas.end(),[](const dts& x,const dts& y){return x.t < y.t;});
        for(i=0;i<M;i++){
            if(pcs[datas[i].s-1]){pcs[datas[i].d-1]=1;}
        }
        for(i=0;i<N;i++){if(pcs[i]){cnt++;}}
        printf("%d\n",cnt);
    }
    return 0;
}

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

#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

int main()
{
    int n, m;
    while (cin >> n >> m, n) {
        vector<int> v(n, 0); 
        v[0] = 1;
        loop(m ,i) {
            int t, s, d;
            cin >> t >> s >> d;
            if (v[s-1] == 1) {
                v[d-1] = 1;
            }
        }
        cout << accumulate(all(v), 0) << endl;
    }
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

//// UnionFind
struct UnionFind{
	vector<int> v;
	UnionFind(int n) : v(n, -1) {}

	int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		if (-v[x] < -v[y]) swap(x, y);
		v[x] += v[y]; v[y] = x;
	}
	bool root(int x) { return v[x] < 0; }
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -v[find(x)]; }
};

int n,m;
PPI ps[22222];

int main(){
	cin.sync_with_stdio(false);
	while(1){
		cin>>n>>m;
		if(n==0)break;
		rep(i,m){
			cin>>ps[i].fi>>ps[i].se.fi>>ps[i].se.se;
			ps[i].se.fi--; ps[i].se.se--;
		}
		sort(ps,ps+m);
		UnionFind uf(n);
		rep(i,m){
			int s=ps[i].se.fi,d=ps[i].se.se;
			if(uf.same(0,s))uf.unite(s,d);
		}
		cout<<uf.size(0)<<endl;
	}
	return 0;
}