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>
#define M 20000
#define N 20001
using namespace std;
struct data{
	int t,s,d;
	bool operator<(const data &c){
		return t < c.t;
	}
};
int main(){
	while(true){
		int n,m;
		int ans=0;
		bool infected[N]={false,};
		data datas[M];
		scanf("%d%d", &n, &m);
		if(n==0&&m==0)
			break;
		for(int i=0;i<m;++i){
			scanf("%d%d%d", &datas[i].t, &datas[i].s, &datas[i].d);
		}
		sort(datas,datas+m);
		infected[1]=true;
		for(int i=0;i<m;++i){
			if( infected[datas[i].s] ){
				infected[datas[i].d]=true;
			}
		}
		for(int i=1;i<=n;++i){
			if( infected[i] )++ans;
		}
		printf("%d\n", ans);
	}
	return 0;
}

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

int N, M;

class Data {
public:
  int t, s, d;
};

Data data[21234];
bool infected[21234];

bool operator < (const Data& a, const Data& b) {
  return a.t < b.t;
}

int main() {

  for(;;) {
    std::cin >> N >> M;
    if( N == 0 and M == 0 ) break;
    for(int i = 0; i < M; ++i) {
      std::cin >> data[i].t >> data[i].s >> data[i].d;
    }
    std::sort(data, data + M);
    for(int i = 1; i <= N; ++i) {
      infected[i] = false;
    }
    infected[1] = true;
    for(int i = 0; i < M; ++i) {
      infected[data[i].d] |= infected[data[i].s];
    }    
    int res = 0;
    for(int i = 1; i <= N; ++i) {
      if( infected[i] ) res += 1;
    }
    std::cout << res << std::endl;
  }  

  return 0;
}

C++: #include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 1100000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	while(1){
		ll n,m; cin >> n >> m;
		if(!n && !m) break;
		vb v(n,false);
		v[0] = true;
		vector<pair<ll,P>> query(m);
		rep(i,m) cin >> query[i].first >> query[i].second.first >> query[i].second.second;
		sort(all(query));
		rep(i,m){
			P p = query[i].second;
			if(v[p.first-1]) v[p.second-1] = true;
		}
		ll ans = 0;
		rep(i,n) if(v[i]) ans++;
		cout << ans << "\n";
	}
}

C++: #include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

int main(void) {
  ll N, M;
  while(cin >> N >> M, N && M) {
    vector<vector<pll>> E(N);
    REP(i, 0, M) {
      ll t, s, d;
      cin >> t >> s >> d;
      s--;
      d--;
      E[s].push_back(pll(t, d));
    }

    vector<bool> used(N, false);
    priority_queue<pll, vector<pll>, greater<pll>> q;
    q.push(pll(0, 0));
    while(q.size()) {
      ll v = q.top().second, t = q.top().first;
      q.pop();

      if(used[v]) continue;
      used[v] = true;

      for(pll p : E[v]) {
        ll nv = p.second, nt = p.first;
        if(nt >= t) {
          q.push(pll(nt, nv));
        }
      }
    }

    ll ans = 0;
    REP(i, 0, N) if(used[i]) ans++;
    cout << ans << endl;
  }
}