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>
#include <map>
using namespace std;
 
const int MAX_N = 20000;
typedef pair<int, pair<int, int > > P;
 
vector<P> v;
bool vis[MAX_N];
 
int main() {
  int N, M;
  while(cin >> N >> M && (N || M)) {
    P p;
    v.clear();
    for(int i = 0; i < M; ++i) {
      cin >> p.first >> p.second.first >> p.second.second;
      --p.second.first; --p.second.second;
      v.push_back(p);
    }
    sort(v.begin(), v.end());
    fill(vis, vis+N, false);
    vis[0] = true;
    int ans = 1;
    for(int i = 0; i < v.size(); ++i) {
      if(vis[v[i].second.first] && !vis[v[i].second.second]) {
        vis[v[i].second.second] = true;
        ++ans;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main(){
	while(1){
		int n, m;
		
		scanf(" %d %d", &n, &m);
		if(n==0) break;
		
		vector< pair<long, pair<int, int> > > d(m);
		
		for(int i=0; i<m; ++i){
			//pairをつかいたい
			scanf(" %ld %d %d", &d[i].first, &d[i].second.first, &d[i].second.second);
		}
		//pairのソート
		sort(d.begin(), d.end());
		
		bool infected[20001];
		for(int i=0; i<=n; ++i) infected[i]=false;
		infected[1]=true;
		
		for(int i=0; i<m; ++i){
			if(infected[ d[i].second.first ])
				infected[ d[i].second.second ]=true;			
		}
		
		int ans=0;
		for(int i=1; i<=n; ++i){
			if(infected[i]) ans++;
		}
		 
		printf("%d\n", ans); 
	}
}

C++: 
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <map>
#include <cstring>
#include <cstdio>
#include <stack>
#define INF 1000000000
#define rep(i,n) for(int i =0;i<n;i++)
using namespace std;
typedef long long int ll;

int main(){
    for(;;){
        int n,m;
        cin >> n >> m;
        if(!n and !m)break;
        vector<pair<ll, pair<int, int> > >pack(m);
        for (int i=0; i<m; i++) {
            ll a;
            int b,c;
            cin >> a >> b >> c;
            pack[i]={a,{b,c}};
        }
        sort(pack.begin(), pack.end());
        vector<int> ka(n+1,0);
        int ans = 1;
        ka[1]=1;
        for (int i=0; i<m; i++) {
            if (ka[pack[i].second.second]==1) {
                continue;
            }else{
                if (ka[pack[i].second.first]==1) {
                    ka[pack[i].second.second]=1;
                    ans++;
                }
            }
        }
        cout << ans << endl;
    }
}

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

int main() {

  while( true ) {

    long long int n, m;
    cin >> n >> m;
    if ( n == 0 ) break;

    vector< pair< long long int, pair< long long int, long long int > > > v;

    for ( long long int i = 0; i < m; i++ ) {

      long long int in_t, in_s, in_d;
      cin >> in_t >> in_s >> in_d;
      in_s--;
      in_d--;
      v.push_back( make_pair( in_t, make_pair( in_s, in_d ) ) );

    }

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

    bool f[20001] = {};

    f[0] = true;

    long long int ans = 1;

    for ( long long int i = 0; i < m; i++ ) {

      if ( f[ v[i].second.first ] == true && f[ v[i].second.second ] == false ) {
	ans++;
	f[ v[i].second.second ] = true;
      }

    }

    cout << ans << endl;

  }

  return 0;

}

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

int main(){
    int n, m;
    while(cin >> n >> m, n+m){
        vector<pair<int, pair<int,int>>> v;
        int t, s, d;
        for(int i = 0; i < m; i++){
            cin >> t >> s >> d;
            v.push_back({t,{s,d}});
        }
        sort(v.begin(), v.end());

        bool infected[20001] = {};
        infected[1] = true;

        for(auto p : v){
            if(infected[p.second.first]){
                infected[p.second.second] = true;
            }
        }

        int cnt = 0;
        for(int i = 1; i <= n; i++) if(infected[i]) cnt++;

        cout << cnt << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<string.h>

using namespace std;
vector<int> ans;
struct edge{int src;int dis;};

int main(){
	while(true){
		int n,m;
		cin >> n >> m;
		if(n == 0 && m == 0) break;
		
		bool virus[20000];
		memset(virus,false,sizeof(virus));
		virus[0] = true;
		
		edge e[20000];
		for(int i = 0;i < m;i++){
			int t,s,d;
			cin >> t >> s >> d;
			e[t-1].src = s;
			e[t-1].dis = d;
		}
		
		for(int i = 0;i < m;i++){
			if(virus[e[i].src - 1]){
				virus[e[i].dis - 1] = true;
			}
		}
		
		int count = 0;
		for(int i = 0;i < n;i++){
			if(virus[i]){
				count++;
			}
		}
		ans.push_back(count);
	}
	
	for(int i = 0;i < ans.size();i++){
		cout << ans[i] << endl;
	}
	return 0;
}