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 <bits/stdc++.h>

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  while (1) {
    int N, M; cin >> N >> M;
    if (N == 0 and M == 0) break;
    vector<T> packets(N);
    REP(i, M) {
      int t, s, d; cin >> t >> s >> d; s--, d--;
      packets[i] = T(t, s, d);
    }
    sort(ALL(packets));
    vector<bool> infected(N, false);
    infected[0] = true;
    for (T packet : packets) {
      int t, s, d; tie(t, s, d) = packet;
      infected[d] =  infected[d] | infected[s];
    }
    cout << accumulate(ALL(infected), 0) << endl;
  }

  return 0;
}

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 <bits/stdc++.h>

using namespace std;

struct packet {
    int time, src, dst;
};

bool operator<(const packet& a, const packet& b)
{
    return a.time<b.time;
}

int main()
{
    int n, m;
    while(cin >> n >> m, n|m)
    {
        bool infected[n+1];
        fill(infected+2, infected+n+1, false);
        infected[1] = true;
        packet ps[m];
        for(int i=0; i<m; i++)
        {
            cin >> ps[i].time >> ps[i].src >> ps[i].dst;
        }
        sort(ps, ps+m);
        int count = 1;
        for(int i=0; i<m; i++)
        {
            if(infected[ps[i].src])
            {
                if(!infected[ps[i].dst]) count++;
                infected[ps[i].dst] = true;
            }
        }
        cout << count << endl;
    }

}

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;

struct edge {
  ll t, s, d;
  bool operator<(struct edge &e) const {
    return t < e.t;
  }
};

ll dfs(ll v, ll t, vector<bool> &used, vector<vector<pll>> &E) {
  if(used[v]) return 0;
  used[v] = true;

  ll ret = 1;
  for(pll p : E[v]) {
    ll u = p.first;
    ll x = p.second;
    if(!used[u] && x >= t) {
      ret += dfs(u, x, used, E);
    }
  }
  return ret;
}

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

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

    vector<vector<pll>> E(N);
    REP(i, 0, M) E[e[i].s].push_back(pll(e[i].d, e[i].t));

    vector<bool> used(N, false);
    cout << dfs(0, 0, used, E) << endl;
  }
}

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)const{
		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;
}