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>
using namespace std;
typedef pair<long long, pair<int, int>> p;
int main() {
    int n, m;
    while (cin >> n >> m, n, m) {
        bool b[20010] = {};
        b[1] = true;
        p a[20010];
        for (int i = 0; i < m; i++)cin >> a[i].first >> a[i].second.first >> a[i].second.second;
        sort(a, a + m);
        for (int i = 0; i < m; i++) 
            if (b[a[i].second.first])b[a[i].second.second] = true;
        int ans = 0;
        for (int i = 1; i <= n; i++)if (b[i])ans++;
        cout << ans << endl;
    }
}

C++: #include <iostream>
using namespace std;
struct set{
  int t;
  int s;
  int d;
};
int main(){
  int n,m,i,j,cnt,source,destination,start,end[20001];
  struct set data[20001];
  while(1){
    for(i=1;i<20001;i++) end[i]=0;
    end[1]=1;
    cin >> n >> m;
    if(n==0&&m==0) break;
    for(i=0;i<m;i++){
      cin >> data[i].t >> data[i].s >> data[i].d;
    }
    for(i=0;i<m;i++){
      for(j=1;j<m;j++){
        if(data[i].t<data[i-1].t) swap(data[i],data[i-1]);
      }
    }
    for(i=0;i<m;i++){
      if(data[i].s==1||data[i].d==1){
	source=data[i].s;
	destination=data[i].d;
        start=i+1;
        break;
      }
    }
    if(source==1){
      end[data[i].d]=1;
      cnt=2;
    }
    if(destination==1) cnt=1;
    for(i=start;i<m;i++){
      if(destination==data[i].s&&end[data[i].d]==0){
	cnt++;
        destination=data[i].d;
        end[data[i].d]=1;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

C++: #include <stdio.h>
#include <algorithm>
#include <tuple>
using namespace std;
int N, M; tuple<int, int, int> D[20000]; bool infected[20000];
int main() {
	while (true) {
		scanf("%d%d", &N, &M);
		if (N == 0 && M == 0) break;
		infected[0] = true;
		for (int i = 1; i < N; i++) infected[i] = false;
		for (int i = 0; i < M; i++) scanf("%d%d%d", &get<0>(D[i]), &get<1>(D[i]), &get<2>(D[i]));
		sort(D, D + M);
		int ret = 1;
		for (int i = 0; i < M; i++) {
			if (infected[--get<1>(D[i])] && !infected[--get<2>(D[i])]) {
				infected[get<2>(D[i])] = true; ret++;
			}
		}
		printf("%d\n", ret);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef tuple<int,int,int> T;
bool infect[20000];
int main() {
    int N,M;
    while(scanf("%d %d",&N,&M),N) {
        memset(infect,0,sizeof(infect));
        infect[0]=1;
        vector<T> v;
        for(int i=0;i<M;i++) {
            int t,s,d;
            scanf("%d %d %d",&t,&s,&d);s--;d--;
            v.push_back(make_tuple(t,s,d));
        }
        sort(v.begin(),v.end());
        for(int i=0;i<v.size();i++) {
            int s=get<1>(v[i]),d=get<2>(v[i]);
            if(infect[s]) infect[d]=1;
        }
        int ans=0;
        for(int i=0;i<N;i++) ans+=infect[i];
        printf("%d\n",ans);
    }
}

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

using namespace std;

typedef long long int lli;

struct P{
	int t;
	int s;
	lli d;
};

bool comp(const P& a, const P& b)
{
	return a.t < b.t;
}

int main()
{
	int n, m, c;
	P a[20001];
	bool af[20001];
	
	while(cin>>n>>m && (n+m)){
		for(int i = 0; i < m; i++){
			cin >> a[i].t >> a[i].s >> a[i].d;
		}
		c = 0;
		fill(af, af+(n+1), false);
		sort(a, a+m, comp);
		af[1] = true;
		
		for(int i = 0; i < m; i++){
			af[a[i].d] = (af[a[i].s]|af[a[i].d]);
		}
		
		for(int i = 1; i <= n; i++){
			if(af[i]){
				c++;
			}
		}
		
		cout << c << endl;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
using triple=pair<int,pair<int,int> >;
#define tm first
#define src second.first
#define dst second.second
const int MAX_N=20010;
int n,m;
triple tp[MAX_N];
bool infected[MAX_N];

int main(){ _;
  while(cin>>n>>m,(n|m)!=0){
    REP(i,m){
      cin>>tp[i].tm>>tp[i].src>>tp[i].dst;
      tp[i].src--;
      tp[i].dst--;
    }
    sort(tp,tp+m);
    REP(i,n)infected[i]=false;
    infected[0]=true;
    REP(i,m)infected[tp[i].dst]|=infected[tp[i].src];
    int cnt=0;
    REP(i,n){
      if(infected[i])cnt++;
    }
    cout<<cnt<<endl;
  }
}

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

struct Data{
  
  int t,s,d;

  bool operator<(const Data& data)const{
    if(data.t != t)return t < data.t;  
    if(data.s != s)return s < data.s;
    return d < data.d;
  }
  
};
int main(){

  int N,M;
  
  while(1){

    cin >>N>>M;
    if(N==0 && M==0)break;
    
    Data data[M];
    for(int i=0 ; i < M ; i++){
      cin >>data[i].t>>data[i].s>>data[i].d;
    }
    
    sort(data,data+M);
    
    bool isinfected[N+1];
    for(int i=1 ; i <= N ; i++)isinfected[i]=false;
    isinfected[1]=true;
    
    int cnt=1;
    for(int i=0 ; i < M ; i++){
      if(isinfected[data[i].s]){
	isinfected[data[i].d]=true;
	cnt++;
      }
    }
    
    cout <<cnt<<endl;
    
  }
  
  return 0;
}

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

using namespace std;

vector<long long int> v;

int main(){
  int n,m,i;
  while(cin >> n >> m, n != 0 || m != 0) {
    int cnt = 1, data[20001][2] = {};
    int in[20001] = {};
    v.clear();
    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;
}