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(){
  long long int n,m,i, k;
  while(cin >> n >> m, n != 0 || m != 0) {
    vector<long long int> v(20100);
    long long int cnt = 1, data[20100][10] = {};
    long long int in[20100] = {};
    in[1] = 1;
    k = 0;
    for(i = 0; i < m; i++) {
      int t,s,g;
      cin >> t >> s >> g;
      data[t][0] = s;
      data[t][1] = g;
      v[k++] = 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;

int main(){
        int n,m;
        while(cin>>n>>m,n){
                vector<tuple<int,int,int>> tsd(m);
                vector<unsigned int> infected(n,0);
                infected[0]=1;
                for(int i=0;i<m;i++){
                        int t,s,d;
                        cin>>t>>s>>d;
                        s--;d--;
                        tsd[i]=make_tuple(t,s,d);
                }
                sort(tsd.begin(),tsd.end());
                for(int i=0;i<m;i++){

                        infected[get<2>(tsd[i])]|=infected[get<1>(tsd[i])];


                }
                int res=accumulate(infected.begin(),infected.end(),0);
                
                cout<<res<<endl;
        }

}

C++: #include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	long long n,m;
	while(cin>>n>>m,n){
		vector<pair<int,pair<int,int> > >v;
		pair<int,pair<int,int> >p;
		long long a[20001]={0},t,s=0;
		a[1]=1;
		r(i,m){
			cin>>p.first>>p.second.first>>p.second.second;
			v.push_back(p);
		}
		sort(v.begin(),v.end());
		r(i,m)if(a[v[i].second.first])a[v[i].second.second]=1;
		r(i,n+1)if(a[i])s++;
		cout<<s<<endl;
	}
}

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

using namespace std;

int main()
{
	for(int n,m;cin>>n>>m,n|m;){
		int ss[m],ds[m];
		for(int i=0;i<m;i++){
			int t,s,d; cin>>t>>s>>d; t--,s--,d--;
			ss[t]=s, ds[t]=d;
		}
		
		bool flg[n];
		fill(flg,flg+n,false);
		flg[0]=1;
		for(int i=0;i<m;i++)
			flg[ds[i]]|=flg[ss[i]];
		
		cout<<count(flg,flg+n,true)<<endl;
	}
	
	return 0;
}

C++: // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2155

#include <iostream>
#include <stdio.h>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;

typedef tuple<int, int, int> data;

int main() {
  int N, M;
  while (scanf("%d%d", &N, &M) != EOF && N) {
    vector<data> V; 
    for (auto i=0; i<M; i++) {
      int t, s, d;
      scanf("%d%d%d", &t, &s, &d);
      V.push_back(make_tuple(t, s, d));
    }
    sort(V.begin(), V.end());
    bool I[20010];
    fill(I, I+20010, false);
    I[1] = true;
    int count = 1;
    for (auto i=0; i<M; i++) {
      int src = get<1>(V[i]);
      int dst = get<2>(V[i]);
      if (I[src] && !I[dst]) {
	I[dst] = true;
	count++;
	// cerr << "src = " << src << ", dst = " << dst << endl; 
      }
    }
    printf("%d\n", count);
  }
}

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

#define rep(i, e) for( int i = 0; i < e; i++ )
typedef vector<int> vec;

struct log{
    int t, s, d, v;
    bool operator<( const log& log ) const{
        return t < log.t;
    }
};

int main(){
    int N, M;
    while( cin >> N >> M, N ){
        vec com(N);
        com[0] = 1;
        int count = 1;
        vector<log> data(M);
        rep(i, M){
            cin >> data[i].t >> data[i].s >> data[i].d;
        }
        sort(data.begin(), data.end() );
        rep(i, M){
            if( com[data[i].s-1] && !com[data[i].d-1] ){
                com[data[i].d-1]++;
                count++;
            }
        }
        //rep(i, M) cout << data[i].t << ' ' << data[i].s << ' ' << data[i].d << ' ' << data[i].v << endl;
        cout << count << endl;
    }
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m,n+m){
    long long a,b,c,k[20001]={},s[22222][2];
    k[1]=1;
    for(int i=0;i<m;i++){
      cin>>a>>b>>c;
      s[a][0]=b;
      s[a][1]=c;
    }

    for(int i=1;i<=m;i++){
      if(k[s[i][0]]==1)k[s[i][1]]=1;
    }
    int ans=0;
    for(int i=1;i<=n;i++)ans+=k[i];
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <utility>
#include <typeinfo>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main() 
{
	int n,m;
	while(cin>>n>>m&&!(n==0&&m==0))
	{
		pll a[20000],b[20000];
		REP(i,m)
		{
			ll x,y,z;
			cin>>x>>y>>z;
			y-=1;z-=1;
			a[i] = make_pair(x,y);
			b[i] = make_pair(x,z);
		}
		sort(a,a+m);
		sort(b,b+m);
		
		bool inf[20000]={};
		inf[0]=true;
		//REP(i,n)cout<<inf[i];cout<<endl;
		REP(i,m){if(inf[a[i].second]){inf[b[i].second]=true;}}
		//REP(i,n)cout<<inf[i];cout<<endl;
		int ans(0);
		REP(i,n)ans+=inf[i];
		
		cout<<ans<<endl;
	}
	return 0;
}