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 <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int N,M;
pair<int,pi> e[20010];
int flag[20010];

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	while(cin>>N>>M && N){
		rep(i,M){
			cin>>e[i].fir>>e[i].sec.fir>>e[i].sec.sec;
			e[i].sec.fir--;e[i].sec.sec--;
		}
		sort(e,e+M);
		memset(flag,0,sizeof(flag));
		flag[0]=1;
		rep(i,M){
			if(flag[e[i].sec.fir]){
				flag[e[i].sec.sec]=1;
			}
		}
		cout<<accumulate(flag,flag+N,0)<<endl;
	}
}

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

using namespace std;

typedef pair<int , pair<int, int> > edge;

int main(){
	int n, m;
	
	while(cin >> n >> m, (n||m)){
		
		int res = 1, t, s, d;
		vector<edge> vc;
		
		for(int i=0; i<m; ++i){
			
			cin>>t>>s>>d;
			vc.push_back(make_pair(t, make_pair(s, d)));
		}
		
		sort(vc.begin(), vc.end());
		
		set<int> infect;
		infect.insert(1);
		
		for(int i=0; i<m; ++i){
			
			if(infect.count(vc[i].second.first) && !infect.count(vc[i].second.second)){
				infect.insert(vc[i].second.second); 
				res++;
			}
		}
		
		cout << res << endl;
	}
	
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int main(){
  int n,m;
  while(cin>>n>>m,n){
    int t,s[20000],d[20000];
    P g[20000];
    for(int i=0;i<m;i++)
      cin>>t>>s[i]>>d[i],g[i]=P(t,i);
    sort(g,g+m);
    int ans=0,b[20001]={};
    b[1]=1;
    for(int i=0;i<m;i++){
      int p=g[i].second;
      if(b[s[p]])b[d[p]]=1;
    }
    for(int i=1;i<=n;i++)ans+=b[i];
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (1) {
		int n, m;
		cin >> n >> m;
		if (!n)break;
		vi v(n, 0);
		v[0] = 1;
		vector<pair<int, pii>> p(m);
		REP(i, m) {
			cin >> p[i].first >> p[i].second.first >> p[i].second.second;
		}
		sort(ALL(p));
		REP(i, m) {
			if (v[p[i].second.first - 1])v[p[i].second.second - 1] = 1;
		}
		int cnt = 0;
		REP(i, n)if (v[i])cnt++;
		cout << cnt << endl;
	}
	return 0;
}

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

int main ()
{
    int n, m;
    while (cin >> n >> m, n || m) {
        vector<int> s(m), d(m);
        vector<bool> v(n+1, false);
        v[1] = true;

        for (int i = 0; i < m; i++) {
            int t;
            cin >> t;
            cin >> s[t - 1] >> d[t - 1];
        }

        for (int i = 0; i < m; i++) {
            if (v[s[i]]) v[d[i]] = true;
        }

        int res = 0;
        for (auto i : v) {
            if (i) res++;
        }

        cout << res << endl;
    }

    return 0;
}