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 <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
 
const int INF = 10000000;



int main(){
	typedef pair<int,pii> pi_ii;
	int n, m;
	while(cin>>n>>m){
		if(n == 0 && m == 0) break;
		vector<pi_ii> v;
		int t, s, d;
		rep(i, m){
			cin>>t>>s>>d;
			v.pb(pi_ii(t, pii(s, d)));
		}
		sort(all(v));
		vi f(n + 1, 0);
		f[1] = 1;
		rep(i, v.size()){
			if(f[v[i].se.fi]){
				f[v[i].se.se] = 1;
			}
		}
		int ans = 0;
		for(int i = 0; i < f.size(); i++){
			if(f[i]) ans++;
		}
		cout<<ans<<endl;
	}
}

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

using namespace std;

int main()
{
	for(int n,m;cin>>n>>m,n|m;){
		vector<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;
		}
		
		vector<int> flg(n);
		fill(begin(flg),end(flg),false);
		flg[0]=1;
		for(int i=0;i<m;i++)
			flg[ds[i]]|=flg[ss[i]];
		
		cout<<count(begin(flg),end(flg),true)<<endl;
	}
	
	return 0;
}

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

#define	mp			make_pair
#define	rep(i,n)	for(int i=0;i<n;i++)

using namespace std;

typedef	pair<int,int>	pii;

int main(){
	for(int m,n;scanf("%d%d",&n,&m),n;){
		pair<int,pii> packet[20000];
		rep(i,m)	scanf("%d%d%d",&packet[i].first,&packet[i].second.first,&packet[i].second.second);
		sort(packet,packet+m);

		bool flg[20000]={};	flg[0]=true;
		rep(i,m){
			int src=packet[i].second.first-1,dst=packet[i].second.second-1;
			flg[dst]|=flg[src];
		}
		printf("%d\n",count(flg,flg+n,true));
	}

	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>

using namespace std;

#define INF 1010001000
#define EPS 1e-10
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef pair<int, int> i_i;
typedef long long int llong;
typedef pair<llong, llong> ll_ll;
typedef struct edge {int f, t;}Edge;


int main()
{
    int n, m;
    while (cin >> n >> m, n) {
        vector<pair<int ,i_i > > data(m);
        vector<bool> infected(n, false);
        rep(i, m) {
            cin >> data[i].first >> data[i].second.first
                >> data[i].second.second;
            data[i].second.first--;
            data[i].second.second--;
        }
        sort(data.begin(), data.end());
        infected[0] = true;
        rep(i, m) {
            infected[data[i].second.second] = 
                (infected[data[i].second.second] || 
                 infected[data[i].second.first]);
        }
        int ret = 0;
        rep(i, n) {
            if (infected[i]) {
                ret++;
            }
        }
        cout << ret << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define X first
#define Y second
using namespace std;
bool f[20000];
int n,m;
pair<int,pair<int,int> >t[20000];
int main(){
	while(cin>>n>>m&&n+m){
	for(int i=1;i<n;i++)f[i]=0;
	f[0]=1;
	for(int i=0;i<m;i++){
		cin>>t[i].X>>t[i].Y.X>>t[i].Y.Y;
		t[i].Y.X--,t[i].Y.Y--;
	}
	sort(t,t+m);
	for(int i=0;i<m;i++){
		if(f[t[i].Y.X])f[t[i].Y.Y]=1;
	}
	int ans=0;
	for(int i=0;i<n;i++)ans+=f[i];
	cout<<ans<<endl;
	}
	return 0;
}

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(0);
    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 < 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;

typedef tuple<int, int, int> TP;

int main() {
  int n, m;
  while (cin >> n >> m, n) {
    vector<TP> tsd;
    for (int i = 0; i < m; i++) {
      int t, s, d;
      cin >> t >> s >> d;
      s--, d--;
      tsd.emplace_back(t, s, d);
    }
    sort(tsd.begin(), tsd.end());
    vector<int> u(n, 0);
    u[0] = 1;
    for (int i = 0; i < m; i++) {
      int t, s, d;
      tie(t, s, d) = tsd[i];
      u[d] |= u[s];
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      ans += u[i];
    }
    cout << ans << endl;
  }

  return 0;
}