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>

using namespace std;

int main(){
  int n,m,i;
  while(cin >> n >> m, n != 0 || m != 0) {
    int cnt = 1, data[20001][2] = {};
    int in[20001] = {};
    vector<int> v(0);
    in[1] = 1;
    for(i = 0; i < m; i++) {
      int t,s,g;
      cin >> t >> s >> g;
      data[t][0] = s;
      data[t][1] = g;
      v.push_back(t);
    }
    sort(v.begin(), v.begin()+m);
    for(i = 0; i < m; i++) {
      if(in[data[v[i]][0]]){
	  if(in[data[v[i]][1]] == 0)
	    {
	      cnt++;
	      in[data[v[i]][1]] = 1;
	    }
	}
    }
      
    cout << cnt << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))

int main(){
    int n,m;
    while(cin>>n>>m,n||m){
        vector<pair<int,pair<int,int>>> v(m);
        vector<int> used(n,0);
        used[0]=1;
        rep(i,m){
            cin>>v[i].first>>v[i].second.first>>v[i].second.second;
        }
        sort(v.begin(),v.end());
        rep(i,m){
            if(used[v[i].second.first-1]) used[v[i].second.second-1]=1;
        }
        int ans=0;
        rep(i,n){
            ans+=used[i];
        }
        cout<<ans<<endl;
    }
}

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

typedef tuple<int, int, int> TP;

int main()
{
	int N, M, t, s, d;
	while (cin >> N >> M, N || M) {
		vector< TP > vec;
		vec.reserve(M);
		for (int i = 0; i < M; i++) {
			cin >> t >> s >> d;
			vec.push_back(TP(t,s,d));
		}
		sort(vec.begin(), vec.end());
		set<int> cmp;
		cmp.insert(1);
		for (int i = 0; i < vec.size(); i++) {
			if (cmp.count(get<1>(vec[i]))) {
				cmp.insert(get<2>(vec[i]));
			}
		}
		cout << cmp.size() << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
typedef pair<int, int> P;

int main(){
  int N, M;
  while(cin>>N>>M && N){
    P t[20000];
    int from[20000], to[20000];
    set<int> virus;
    virus.insert(1);
    REP(i, M){
      cin>>t[i].first>>from[i]>>to[i];
      t[i].second = i;
    }
    sort(t, t + M);
    REP(i, M){
      int idx = t[i].second;
      if(virus.count(from[idx])){
        virus.insert(to[idx]);
      }
    }
    cout<<virus.size()<<endl;
  }
  return 0;
}

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

using namespace std;

int main(){
  int n,m;
  for(;cin>>n>>m,n;)
    {
      bool virus[n];
      vector<pair<int, pair<int,int> > > data;

      memset(virus,false,sizeof(virus));
      virus[0]=true;
      for(int i=0;i<m;i++)
	{
	  int t,s,d;
	  cin>>t>>s>>d;
	  s--;
	  d--;
	  data.push_back(make_pair(t,make_pair(s,d)));
	}
      sort(data.begin(),data.end());
      for(int i=0;i<m;i++)
	{
	  if(virus[data[i].second.first])
	    virus[data[i].second.second]=true;
	}
      int ans=0;
      for(int i=0;i<n;i++)
	{
	  if(virus[i])
	    ans++;
	}
      cout<<ans<<endl;
    }

}

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 P {
	long long time, from, to;
};
bool operator<(P a, P b) { return a.time < b.time; }
bool operator>(P a, P b) { return a.time > b.time; }
bool a[20001];
P p[20000];
int main() {
	long long n, m;
	while (cin >> n >> m&&(n != 0 ||m != 0)) {
		for (long long i = 1; i <= n; i++) a[i] = false;
		a[1] = true;
		for (long long i = 0; i < m; i++) {
			cin >> p[i].time >> p[i].from >> p[i].to;
		}
		sort(p, p + m);
		long long sum = 1;
		for (int i = 0; i < m; i++) {
			if (a[p[i].from]) {
				if (!a[p[i].to]) sum++;
				a[p[i].to] = true;
			}
		}
		if(n!=0)cout << sum << endl;
		else cout << 0 << endl;
	}
}

C++: #include<iostream>
#include<vector>
using namespace std;int main(){for(int N,M,i;cin>>N>>M,N;cout<<N<<endl){vector<int>v(N+1),s(M+1),d(M+1);for(i=0;i++<M;cin>>s[N]>>d[N])cin>>N;v[1]=N=1;for(i=0;i++<M;)if(v[s[i]])v[d[i]]=1&&v[d[i]]||N++;}}