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;
struct log{
  int T,s,d;
  bool operator<(const log &a)const{
    return T<a.T;
  }
};
const int MAX_N=30000;
int parent[MAX_N];
int depth[MAX_N];

void init(int n){
  for(int i=0;i<n;i++){
    parent[i]=i;
    depth[i]=0;
  }
}

int find(int x){
  if(parent[x]==x){
    return x;
  }else{
    return parent[x]=find(parent[x]);
  }
}

void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y)return;
  if(depth[x]<depth[y]){
    parent[x]=y;
  }else{
    parent[y]=x;
    if(depth[x]==depth[y])depth[x]++;
  }
}

bool same(int x,int y){
  return find(x)==find(y);
}

log l[30000];
int main(){
  int n,m;
  while(cin>>n>>m,n){
    init(n);
    for(int i=0;i<m;i++)
      cin>>l[i].T>>l[i].s>>l[i].d;
    sort(l,l+m);
    for(int i=0;i<m;i++){
      if(same(1,l[i].s)){
	if(!same(1,l[i].d))unite(1,l[i].d);
      }
    }
    int ans=0;
    for(int i=0;i<n;i++)
      if(parent[i]==1)ans++;

    cout << ans << endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
 
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
 
struct edge{ int from, to, cost; };
 
 
int n, m;
bool used[20005];
 
bool comp(const edge& e1, const edge& e2)
{
    return e1.cost < e2.cost;
}
 
int main()
{
    while (cin >> n >> m, n)
    {
        edge es[20005];
        REP(i, m)
        {
            int a, b, c;
            cin >> a >> b >> c;
            c--; b--;
            es[i] = edge{ b, c, a };
        }
        sort(es, es + m, comp);
        memset(used, false, sizeof(used));
        used[0] = true;
        REP(i, m)
        {
            if (used[es[i].from]) used[es[i].to] = true;
        }
        int cnt = 0;
        REP(i, n)
        {
            if (used[i]) cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
struct pac{
  int t;
  int o;
  int m;
  bool operator<(const pac& right)const{
    return t==right.t ? o<right.o:t < right.t ;
  }
};
int main(){
  while(1){
    int n,x;
    cin >> n >> x;
    if(n==0&&x==0)break;
    vector<pac> p(x);
    vector<int> v(n+1,0);
    int c=1;
    v[1]=1;
    for(int i=0;i<x;i++){
      cin >> p[i].t >> p[i].o >> p[i].m;
    }
    sort(p.begin(),p.end());
    for(int i=0;i<x;i++){
      if(v[p[i].o]==1){if(v[p[i].m]==0)c++;v[p[i].m]=1;
	}
    }
    cout << c<< endl; 
  }
  return 0;

}

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

using namespace std;

int main(void)
{
	int n, m;
	while (cin >> n >> m, n || m){
		vector < pair <int, int> > data(m);
		pair <int, int> edge[20050];
		for (int i = 0; i < 20050; i++){
			edge[i].first = edge[i].second = -1;
		}
		int t, s, d;
		for (int i = 0; i < m; i++){
			cin >> t >> s >> d;
			data[i].first = t;
			data[i].second = i;
			edge[i].first = s;
			edge[i].second = d;
		}
		sort(data.begin(), data.end());

		bool infect[20050] = {false};
		infect[1] = true;
		for (int i = 0; i < m; i++){
			int from = edge[data[i].second].first;
			int goal = edge[data[i].second].second;
			if (infect[from]){
				infect[goal] = true;
				// cout << goal << " is infect" << endl;
			}
		}

		int ret = 0;
		for (int i = 0; i <= 20050; i++){
			if (infect[i]) ret++;
		}
		cout << ret << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m,n){
    long long a,b,c,k[20001]={};
    vector<pair<long long,pair<int,int> > > s;
    k[1]=1;
    for(int i=0;i<m;i++){
      cin>>a>>b>>c;
      s.push_back(make_pair(a,make_pair(b,c)));
    }
    sort(s.begin(),s.end());
    for(int i=0;i<m;i++){
      if(k[s[i].second.first]==1)k[s[i].second.second]=1;
    }
    int ans=0;
    for(int i=1;i<=n;i++)ans+=k[i];
    cout<<ans<<endl;
  }
  return 0;
}

C++: //#include <bits/stdc++.h>
//#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <bitset>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <cmath>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <cctype>
#include <fstream>

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000			 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979
#define MAXI 7500000

//.size()はunsigned int　0-1をするとオーバーフローする

using namespace std;
typedef long long int ll;
typedef pair<long long int  ,long long int> P;

//int dy[5] = { 0,0,1,-1,0 };
//int dx[5] = { 1,-1,0,0,0 };

int dy[5] = {-1, 0, 1, 0, 0};
int dx[5] = {0, -1, 0, 1, 0};

int main(void)
{
	while(1){
		int n, m;

		cin >> n >> m;
		if(n==0&&m==0){
			break;
		}
		int t, s, d;
		vector<pair<int, pair<int,int> > > pa(m);
		vector<int> com(n + 1,0);
		int count = 0;
		com[1] = 1;
		FOR(i, 0, m - 1)
		{
			cin >> t >> s >> d;
			pa[i].first = t;
			pa[i].second.first=s;
			pa[i].second.second = d;
		}
		sort(pa.begin(), pa.end());
		FOR(i,0,m-1){
			if(com[pa[i].second.first]==1){
				com[pa[i].second.second] = 1;
			}
		}

		FOR(i,1,n){
			if(com[i]==1){
				count++;
			}
		}

		cout << count << endl;
	}
}