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<bits/stdc++.h>
using namespace std;
#define t first
#define s second.first 
#define d second.second

int main(){
  vector <pair<int ,pair<int ,int> > > a;
  while(1){
  int n,m;
  int b[20001]={};
  b[1]=1;
  cin>>n>>m;
  if(n==0 && m==0)break;
  a.resize(m);
  for(int i=0;i<m;i++)
    cin>>a[i].t>>a[i].s>>a[i].d;

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

  int count=1;
  for(int i=0;i<m;i++)
    if(b[a[i].s]==1 && b[a[i].d]==0){
	b[a[i].d]=1;
	count++;
    }
  cout<<count<<endl;
  }

  return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int, 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>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

typedef pair<int, pair<int, int> > Ep;

const int MAX_N = 20001;
int N, M;
vector<Ep> E;
bool vis[MAX_N];

int main() {
  while(cin >> N >> M && (N || M)) {
    E.clear();
    for(int i = 0; i < M; ++i) {
      Ep e;
      cin >> e.first >> e.second.first >> e.second.second;
      --e.second.first; --e.second.second;
      E.push_back(e);
    }

    sort(E.begin(), E.end());
    fill(vis, vis+N, false);
    vis[0] = true;
    int ans = 1;
    for(int i = 0; i < E.size(); ++i) {
      pair<int, int> &p = E[i].second;
      if(vis[p.first] && !vis[p.second]) {
	vis[p.second] = true;
	++ans;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <tuple>
using namespace std;
typedef tuple<int, int, int> T;

int n, m;
T rec[20000];

int main() {
	int i;
	
	while (cin >> n >> m) {
		if (!n) break;
		for (i = 0; i < m; i++) {
			int t, s, d;
			cin >> t >> s >> d; s--; d--;
			rec[i] = T(t, s, d);
		}
		sort(rec, rec + m);
		
		bool infected[20000] = {false};
		infected[0] = true;
		for (i = 0; i < m; i++) {
			int s = get<1>(rec[i]);
			int d = get<2>(rec[i]);
			if (infected[s]) infected[d] = true;
		}
		
		int ans = 0;
		for (i = 0; i < n; i++) ans += infected[i];
		cout << ans << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define t first
#define s second.first 
#define d second.second

int main(){
  vector <pair<int ,pair<int ,int> > > a;


  while(1){
  int n,m;
  int b[20001]={};
  b[1]=1;
  cin>>n>>m;
  if(n==0 && m==0)break;
  a.resize(m);
  for(int i=0;i<m;i++)
    cin>>a[i].t>>a[i].s>>a[i].d;

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

  int count=1;
  for(int i=0;i<m;i++)
    if(b[a[i].s]==1){
      b[a[i].d]=1;
      count++;
    }
  cout<<count<<endl;
  }

  return 0;
}

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

int main(){
    while(1){
        int n,m;
        cin >> n >> m;
        if(n==0) break;

        vector< pair<int,pair<int,int> > > logs(m);
        for(int i=0; i<m; i++){
            int t,s,d;
            cin >> t >> s >> d;
            logs[i] = make_pair(t, make_pair(s,d));
        }
        sort(logs.begin(), logs.end());

        vector<bool> dead(n+1, false);
        dead[1]=true;
        int cnt=1;
        for(int i=0; i<m; i++){
            int send = logs[i].second.first;
            int dest = logs[i].second.second;
            if(dead[send] && !dead[dest]){
                dead[dest]=true;
                cnt++;
            }
        }
        
        cout << cnt << endl;
    }
    return 0;
}

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<iostream>
#include<vector>
#include<string.h>

using namespace std;
vector<int> ans;
struct edge{int to;int time;};

bool virus[20000];
void dfs(vector<edge> e[],int cur,int time){
	for(int i = 0;i < e[cur-1].size();i++){
		edge te = e[cur-1][i];
		if(te.time > time){
			if(virus[cur-1]){
				virus[te.to-1] = true;
				dfs(e,te.to,te.time);
			}
		}
	}
}

int main(){
	while(true){
		int n,m;
		cin >> n >> m;
		if(n == 0 && m == 0) break;

		memset(virus,false,sizeof(virus));
		virus[0] = true;
		
		vector<edge> e[20000];
		for(int i = 0;i < m;i++){
			int t,s,d;
			cin >> t >> s >> d;
			edge te;
			te.to = d;
			te.time = t;
			e[s - 1].push_back(te);
		}
		
		dfs(e,1,0);
		
		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;
}