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<map>
#include<algorithm>
using namespace std;

typedef pair<int,int>P;
typedef pair<int,P> PP;
const int MAX_N=2*1e5+1;
PP data[MAX_N];
bool infected[MAX_N];
int main(){
	int n,m;
	while(cin>>n>>m && n){
		fill(infected,infected+MAX_N,false);
		infected[1]=true;
		for(int i=0;i<m;i++){
			int t,s,d;
			cin>>t>>s>>d;
			data[i]=PP(t,P(s,d));
		}
		sort(data,data+m);
		for(int i=0;i<m;i++)infected[data[i].second.second]|=infected[data[i].second.first];
		int ans=0;
		for(int i=1;i<=n;i++)ans+=infected[i];
		cout<<ans<<endl;
	}
}

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 E {
	long long time, to;
};
struct P {
	long long time, pos;
};
bool operator<(P a, P b) { return a.time < b.time; }
bool operator>(P a, P b) { return a.time > b.time; }
long long a[20001], inf = 8000000000000000;
vector<E>e[20001];
int main() {
	int n, m;
	while (cin >> n >> m&&n != 0 && m != 0) {
		for (int i = 1; i <= n; i++) {
			e[i].clear();
			a[i] = inf;
		}
		for (int i = 0; i < m; i++) {
			int t, s, d;
			cin >> t >> s >> d;
			e[s].push_back(E{ t,d });
		}
		priority_queue<P, vector<P>, greater<P>>p;
		a[1] = 0;
		p.push(P{ 0,1 });
		while (!p.empty()) {
			P t = p.top(); p.pop();
			if (a[t.pos] != inf) {
				for (int i = 0; i < (int)e[t.pos].size(); i++) {
					if (a[e[t.pos][i].to] > a[t.pos] + e[t.pos][i].time) {
						a[e[t.pos][i].to] = a[t.pos] + e[t.pos][i].time;
						p.push(P{ a[e[t.pos][i].to],e[t.pos][i].to });
					}
				}
			}
		}
		int sum = 0;
		for (int i = 1; i <= n; i++) {
			if (a[i] != inf) sum++;
		}
		cout << sum << endl;
	}
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n, m;

struct UnionFind {
	int par[201000];
	int rank[201000];

	void init() {
		for (int i = 0; i < 201000; i++) {
			par[i] = i;
			rank[i] = 1;
		}
	}

	int find(int x) {
		if (par[x] == x) return x;
		return par[x] = find(par[x]);
	}

	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;
		if (rank[x] < rank[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (rank[y] == rank[x])rank[x]++;
		}
	}

	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

UnionFind uf;

int main() {
	while (cin >> n >> m&&n + m) {
		uf.init();
		vector<pair<int, P>> vip;
		rep(i, m) {
			int t, s, d;
			cin >> t >> s >> d;
			vip.push_back({ t,{s,d} });
		}
		sort(ALL(vip));
		rep(i, m) {
			int s = vip[i].second.first, d = vip[i].second.second;
			if (uf.same(1, s)) {
				uf.unite(s, d);
			}
		}
		int ans = 0;
		FOR(i, 1, n + 1) {
			ans += (uf.find(i) == 1);
		}
		cout << ans << endl;
	}
}

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>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	long long n,m;
	while(cin>>n>>m,n){
		long long a[20001]={0},b[1000000001][2]={0},t,s=0;
		a[1]=1;
		r(i,m){
			cin>>t;
			cin>>b[t][0]>>b[t][1];
		}
		r(i,1000000001)if(a[b[i][0]])a[b[i][1]]=1;
		r(i,1000000001)if(a[i])s++;
		cout<<s<<endl;
	}
}

C++: #include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
int main(void)
{
  for(;;){
    int n,m;
    cin >> n >> m;
    if(!n&&!m) return 0;
    vector<bool> infected;
    infected.assign(n+1,false);
    infected[1]=true;
    vector<pair<int,pair<int,int> > > sendlog;
    REP(i,m){
      int t,s,d;
      cin >> t >> s >> d;
      sendlog.push_back(make_pair(t,make_pair(s,d)));
    }
    SORT(sendlog);
    REP(i,sendlog.size())
      infected[sendlog[i].second.second]=infected[sendlog[i].second.second]||infected[sendlog[i].second.first];
    int answer=0;
    REP(i,infected.size()) if(infected[i]) ++answer;
    cout << answer << endl;
  }
}