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 <algorithm>
#include <vector>

using namespace std;

struct Packet {
  int t, s, d;

  Packet() = default;
  Packet(int t, int s, int d): t(t), s(s), d(d) { }

  bool operator<(const Packet& p) const {
    return t < p.t;
  }
};

int main() {
  while (true) {    
    int N, M;
    cin >> N >> M;

    if (N + M == 0) {
      break;
    }

    bool infected[20001] = { true };

    vector<Packet> packet(M);
    for (int i = 0; i < M; i++) {
      int t, s, d;
      cin >> t >> s >> d;
      packet[i] = Packet(t, s - 1, d - 1);
    }
    sort(packet.begin(), packet.end());

    for (int i = 0; i < M; i++) {
      if (infected[packet[i].s]) {
        infected[packet[i].t] = true;
      }
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
      if (infected[i]) {
        ans++;
      }
    }

    cout << ans << endl;
  }

  return 0;
}

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

using namespace std;

// #define LOG(...) fprintf(stderr, __VA_ARGS__)
#define LOG(...)
#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for(int i = (int)(n - 1); i >= 0; --i)
#define RFOR(i, a, b) for(int i = (int)(b - 1); i >= (int)(a); --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SQ(n) (n) * (n)
#define BIT(x, i) (((x) >> (i)) & 1)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vc> vvc;
typedef vector<vll> vvll;

int main() {
  int N, M;
  while(cin >> N >> M, N) {
    vc virus(N);
    vector<pair<int, pii>> log(M);
    REP(i, M){
      cin >> log[i].first >> log[i].second.first >> log[i].second.second;
      log[i].second.first--;
      log[i].second.second--;
    }
    SORT(log);

    LOG("fuga\n");
    virus[0] = true;
    for(auto p : log) {
      LOG("%d -> %d\n", p.second.first, p.second.second);
      virus[p.second.second] |= virus[p.second.first];
    }
    LOG("hogehgoe\n");
    cout << count(ALL(virus), 1) << endl;
  }
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#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 mt make_tuple
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n,m;
	while(cin>>n>>m,n){
		vip in(m);
		rep(i,m)cin>>in[i].first>>in[i].second.first>>in[i].second.second;
		sort(all(in));
		vi out(n+1);
		out[1]=1;
		rep(i,m)out[in[i].second.second]|=out[in[i].second.first];
		int co=0;
		rep(i,n+1)co+=out[i];
		cout<<co<<endl;
	}
}

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

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
typedef long long ll;

int main()
{
    int n,m;
    while(cin >> n >> m) {
        if(n == 0 && m == 0) break;
        
        vector<pair<int,pair<int,int> > > v(m);
        rep(i,m) cin >> v[i].first >> v[i].second.first >> v[i].second.second;

        sort(v.begin(),v.end());

        int id = 1;
        int ans = 1;

        rep(i,m) {
            int s = v[i].second.first;
            int t = v[i].second.second;

            if(s == id) {
                id = t;
                ans++;
            }
        }

        cout << ans << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;

vector<int> t, s, d;
bool cmp(int i, int j) { return t[i] < t[j]; }

int main() {
    int N, M;
    while (cin >> N >> M, N) {
        vector<int> res(N, 0); res[0] = 1;
        t.resize(M); s.resize(M); d.resize(M);
        for (int i = 0; i < M; ++i) cin >> t[i] >> s[i] >> d[i], --s[i], --d[i];
        vector<int> ind(M); iota(ind.begin(), ind.end(), 0);
        sort(ind.begin(), ind.end(), cmp);
        for (auto i : ind) {
            if (res[s[i]] == 1) res[d[i]] = 1;
        }
        int num = 0;
        for (auto r : res) num += r;
        cout << num << endl;
    }
}