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

int infe[20010];

int main(){
	int N,M;
	while(cin >> N >> M && N){
		vector< pair<int, pair<int,int> > > v;
		for(int i = 0 ; i < M ; i++){
			int t,s,d;
			cin >> t >> s >> d;
			v.push_back(make_pair(t,make_pair(s,d)));
		}
		for(int i = 0 ; i < 20010 ; i++)
			infe[i] = 0;
		infe[1] = 1;
		sort(v.begin(),v.end());
		for(int i = 0 ; i < M ; i++){		
			if( infe[v[i].second.first] ){
				infe[v[i].second.second] = 1;
			}
		}
		int ans = 0;
		for(int i = 0 ; i < 20010 ; i++)
			ans += infe[i];
		cout << ans << endl;
	}
}

C++: 
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n,m;
  while(1){
    cin>>n>>m;
    if(n==0 && m==0)break;
    vector<bool> v(n,false);
    pair< int,pii > p[200000];
    rep(i,m){
      cin>>p[i].first>>p[i].second.first>>p[i].second.second;
      p[i].second.first--;
      p[i].second.second--;
    }
    sort(p,p+m);
    v[0]=true;
    rep(i,m)
      if(v[p[i].second.first])v[p[i].second.second]=true;
    int ans=0;
    rep(i,n)if(v[i])ans++;
    cout<<ans<<endl;
  }
}

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

int N, M;
vector< vector< pair<int, int> > > v;
vector<bool> used;

int dfs(int pos, int time){
    
    used[pos] = true;
    int res = 0;
    for(int i = 0; i < v[pos].size(); i++){
        if(used[ v[pos][i].second ] == true) continue;
        if(v[pos][i].first > time){
            res += dfs(v[pos][i].second, v[pos][i].first);
        }
    }

    return res + 1;
}

int main(void){
    while(cin >> N >> M, N | M){
        v = vector<vector<pair<int, int> > >(N, vector< pair<int, int> >(0));
        used = vector<bool>(N, false);
        for(int i = 0; i < M; i++){
            int t, s, d; cin >> t >> s >> d;
            s--; d--;
            v[s].push_back(make_pair(t, d));
        }
        for(int i = 0; i < N; i++) sort(v[i].begin(), v[i].end());
        cout << dfs(0, 0) << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,M;
    cin >> N >> M;
    while(N != 0){
        vector<int> virus(N,false);
        virus[0] = true;
        vector<pair<int,pair<int,int>>> G(M);
        for(int i=0; i<M; i++){
            cin >> G[i].first >> G[i].second.first >> G[i].second.second;
            G[i].second.first--;
            G[i].second.second--;
        }
        sort(G.begin(),G.end());
        for(int i=0; i<M; i++){
            virus[G[i].second.second] |= virus[G[i].second.first];
        }
        int ans = 0;
        for(int i=0; i<N; i++){
            ans += virus[i];
        }
        cout << ans << endl;
        cin >> N >> M;
    }
    return 0;
}

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

using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m;
    while (true)
    {
        cin >> n >> m;
        if (n == 0)
            break;
        bool infected[n + 1];
        for (int i = 2; i < n + 1; i++)
            infected[i] = false;
        infected[1] = true;
        int s[m + 1], d[m + 1];
        vector<pair<int, int>> t;
        for (int i = 1; i <= m; i++)
        {
            int tmp;
            cin >> tmp >> s[i] >> d[i];
            t.push_back(make_pair(tmp, i));
        }
        sort(t.begin(), t.end());
        for (int i = 0; i < m; i++)
        {
            int idx = t[i].second;
            if (infected[s[idx]])
                infected[d[idx]] = true;
        }
        int res = 0;
        for (int i = 1; i <= n; i++)
            if (infected[i])
                res++;
        cout << res << endl;
    }
}