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;
    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.end());
    for(i = 0; i < v.size(); 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<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n,m;
	while(cin>>n>>m,n||m){
		bool infect[n+1];
		rep(i,n+1)infect[i]=false;
		infect[1]=true;
		long long ans=1;
		long long t[m];
		int s[m],d[m];
		rep(i,m)cin>>t[i]>>s[i]>>d[i];
		for(int i=m-1;i>=0;i--){
			for(int j=0;j<i-1;j++){
				if(t[j]>t[j+1]){
					long long alt=t[j];
					t[j]=t[j+1];
					t[j+1]=alt;
					alt=s[j];
					s[j]=s[j+1];
					s[j+1]=alt;
					alt=d[j];
					d[j]=d[j+1];
					d[j+1]=alt;
				}
			}
		}
		rep(i,m){
			if(infect[s[i]]){
				ans++;
				infect[d[i]]=true;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

int main()
{
  vector<pair<int,pair<int,int> > > PC;
  int N,M,t,s,d,c,start;
  bool p[20001];

  while(1){
    cin>>N>>M;
    if(N==0&&M==0)break;
    PC.clear();
    start=0;
    for(int i=0;i<N+1;i++)p[i]=false;
    for(int i=0;i<M;i++){
      cin>>t>>s>>d;
      PC.push_back(make_pair(t,make_pair(s-1,d-1)));
    }
    c=1;
    p[0]=true;
    sort(PC.begin(),PC.end());

    for(int i=0;i<M;i++){
      if(p[PC[i].second.first])p[PC[i].second.second]=true;
    }
    for(int i=1;i<N+1;i++)if(p[i])c++;
    cout<<c<<endl;
  }
  return 0;
}

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

struct sta{
  int t;
  int from;
  int to;
};

int main(){
  while(1){
    int n,m;
    cin >> n >> m;
    if(n==0) return 0;
    vector<sta> e(m);
    int t,s,d;
    for(int i=0;i<m;i++){
      cin >> e[i].t >> e[i].from >> e[i].to;
      e[i].from--,e[i].to--;
    }
    sort(e.begin(),e.end(),[](const sta &l, const sta &r){
	    return l.t < r.t;
    });
    vector<int> a(n,0);
    a[0]=1;
    int count=1;
    for(int i=0;i<m;i++){
      if(a[e[i].from]==1) if(a[e[i].to]==0) a[e[i].to]=1,count++;
    }
    cout << count << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main(){
	int n,m;
	while(cin >> n >> m,n){
		vector<pair<int,pair<int,int>>> v;
		for(int i=0;i<m;i++){
			int t,s,d;
			cin >> t >> s >> d;
			v.emplace_back(make_pair(t,make_pair(s,d)));
		}
		bool infected[20000];
		for(int i=0;i<20000;i++) infected[i] = false;
		infected[0] = true;
		sort(v.begin(),v.end());
		for(auto x:v){
			if(infected[x.second.first-1]){
				infected[x.second.second-1] = true;
			}
		}
		int ans = 0;
		for(int i=0;i<20000;i++){
			if(infected[i]){
				//cout << i << endl;
				ans++;
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}

C++: #include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 20000
 
struct edge{
    int from, to, cost;
 
    edge(int from = -1, int to = -1, int cost = -1) 
	: from(from), to(to), cost(cost) {}
 
    bool operator < (const edge &e)const{
	return cost < e.cost;
    }
};
 
int main(){
    int N, M, t, s, d;
 
    while(cin >> N >> M , N){
	edge e[MAX];
 
	for(int i = 0 ; i < M ; i++){
	    cin >> t >> s >> d;
	    e[i] = edge(s-1, d-1, t);
	}
     
	sort(e, e+M);
	bool check[MAX] = {false};
	check[0] = true;
 
	for(int i = 0 ; i < M ; i++){
	    if(check[e[i].from]){
		check[e[i].to] = true;
	    }
	}
     
	int ans = 0;
	for(int i = 0 ; i < N ; i++){
	    if(check[i]) ans++;
	}
	cout << ans << endl;
    }
    return 0;
}