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<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
struct UnionFind{
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unionSet(int x,int y){
        x=root(x);y=root(y);
        if(x==y)return 0;
        if(data[y]<data[x])swap(x,y);
        data[x]+=data[y],data[y]=x;
        return 1;
    }
    bool findSet(int x,int y){
        return root(x)==root(y);
    }
    int root(int x){
        return data[x]<0 ? x : data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};
int main(){
	int n,m;
	while(cin>>n>>m,n+m){
		vip in(m);
		rep(i,m){
			int a,b,c;
			cin>>a>>b>>c;
			b--;c--;
			in[i]=pip(a,pii(b,c));
		}
		sort(all(in));
		UnionFind uf(n);
		rep(i,m){
			if(uf.root(in[i].second.first)==uf.root(0))uf.unionSet(in[i].second.first,in[i].second.second);
		}
		cout<<uf.size(0)<<endl;
	}
}

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

using i64 = int64_t;

struct Packet{
    int t, s, d;
    bool operator<(const Packet &obj)const{
        return t < obj.t;
    };
};

int main(){
    int n, m;
    while(cin >> n >> m, n != 0){
        vector<Packet> v;
        for(int i=0;i<m;++i){
            int t, s, d;
            cin >> t >> s >> d;
            v.push_back((Packet){t, s, d});
        }
        sort(v.begin(), v.end());
        set<int> infected;
        infected.insert(1);
        for(auto e: v){
            int s = e.s, d = e.d;
            if(infected.count(s))infected.insert(d);
        }
        cout << infected.size() << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int, pair<int, int>> p;
int main() {
	int n, m;
	while (cin >> n >> m, n && m) {
		bool b[20010] = {};
		b[1] = true;
		p a[20010];
		for (int i = 0; i < m; i++)cin >> a[i].first >> a[i].second.first >> a[i].second.second;
		sort(a, a + m);
		for (int i = 0; i < m; i++) 
			if (b[a[i].second.first])b[a[i].second.second] = true;
		int ans = 0;
		for (int i = 1; i <= n; i++)if (b[i])ans++;
		cout << ans << endl;
	}
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
/*
template<class... T>
ostream& operator<<(ostream& os, tuple<T...>& t) {
	for (size_t i = 0; i < tuple_size< tuple<T...> >::value; ++i) {
		if (i) os << " ";
		os << get<0>(t);
	}
	return os;
}
*/
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int N, M;
	while ( cin >> N >> M, N || M ) {
		vector< tuple<int, int, int> > v;
		REP(i, M) {
			int t, from, to; cin >> t >> from >> to; --from, --to;
			v.emplace_back(t, from, to);
		}
		sort( ALL(v) );
		vector<bool> isInfected(N, false); isInfected[0] = true;
		REP(i, M) {
			int t, from, to; tie(t, from, to) = v[i];
			if (isInfected[from]) isInfected[to] = true;
		}
		int ans = 0;
		REP(i, N) {
			ans += isInfected[i];
		}
		cout << ans << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cstring>

using namespace std;

int n, m;
bool bad[20001];

int main(){
    while (cin >> n >> m && n | m){
        vector<vector<int>> record(m, vector<int>(3));
        for (int i = 0; i < m; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                cin >> record[i][j];
            }
        }
        sort(record.begin(), record.end());
        memset(bad, 0, sizeof(bad));
        bad[1] = true;
        for (auto & r : record){
            bad[r[2]] |= bad[r[1]];
        }
        cout << count(bad + 1, bad + 1 + n, true) << endl;
    }
}

C++: #include<iostream>
#include<algorithm>
#define X first
#define Y second
using namespace std;
bool f[20000];
int n,m;
pair<int,pair<int,int> >t[20000];
int main(){
	while(cin>>n>>m&&n+m){
	for(int i=1;i<n;i++)f[i]=0;
	f[0]=1;
	for(int i=0;i<m;i++){
		cin>>t[i].X>>t[i].Y.X>>t[i].Y.Y;
		t[i].Y.X--,t[i].Y.Y--;
	}
	sort(t,t+m);
	for(int i=0;i<m;i++){
		if(f[t[i].Y.X])f[t[i].Y.Y]=1;
	}
	int ans=0;
	for(int i=0;i<n;i++)ans+=f[i];
	cout<<ans<<endl;
	}
	return 0;
}