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;
typedef pair<long long, pair<int, int>> p;
int main() {
	int n, m;
	while (cin >> n >> m) {
		if (n == 0 && m == 0)return 0;
		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<stdio.h>
#include<iostream>
using namespace std;

int main(){

	
	
	int N,M;
	while(1){
		cin>>N>>M;if(N==0&&M==0)break;
		int s[20001]={};
		int r[20001]={};
		int m[20001]={};
		bool F[20001]={};
		F[1]=true;
		int c=0;
		int x,y,z;
		for(int i=0;i<M;i++)
		{cin>>x>>y>>z;
		m[i]=x;
		s[i]=y;r[i]=z;}
		for(int i=0;i<M;i++)
			for(int j=M-1;j>i;j--)
				if(m[j]<m[j-1]){
					int t=m[j];m[j]=m[j-1];m[j-1]=t;
					t=s[j];s[j]=s[j-1];s[j-1]=t;
					t=r[j];r[j]=r[j-1];r[j-1]=t;

				}
		for(int i=0;i<M;i++){
	
		
			{if(F[s[i]]==true&&r[i]!=1)F[r[i]]=true;}}
		for(int i=0;i<=N;i++)
			if(F[i]==true)c++;
		cout<<c<<endl;
	}
	return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int) (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9+7

using namespace std;
bool infected[20000];

struct logs{
  int t, f, d;
  logs(int t, int f, int d) : t(t), f(f), d(d) {}
  logs() : t(INF), f(0), d(0) {}
  bool operator<(logs &x)const{
    if(t < x.t) return true;
    return false;
  }
};

array<logs, 20000> data;

int main(){
  int n, m;
  while(cin >> n >> m and n + m){
    memset(infected, 0, sizeof(infected));
    REP(i, 20000){
      data[i] = logs();
    }
    REP(i, m){
      int t, s, d;
      cin >> t >> s >> d; s--; d--;
      data[i] = logs(t, s, d);
    }
    sort(ALL(data));
    infected[0] = true;
    REP(i, m){
      if(infected[data[i].f]) infected[data[i].d] = true;
      else infected[data[i].d] = false;
    }
    int res = 0;
    REP(i, n) if(infected[i]) res++;
    cout << res << endl;
  }
}

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

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n,m;
  while(true){
    cin >> n >> m;
    if(n==0) break;
    bool infected[n+1];
    for(int i=2;i<n+1;i++) infected[i]=false;
    infected[1]=true;
    int s[m+1],d[m+1];
    vector<pair<int,int>> t;
    for(int i=1;i<=m;i++){
      int tmp;
      cin >> tmp >> s[i] >> d[i];
      t.push_back(make_pair(tmp,i));
    }
    sort(t.begin(),t.end());
    for(int i=0;i<m;i++){
      int idx=t[i].second;
      if(infected[s[idx]]) infected[d[idx]]=true;
    }
    int res=0;
    for(int i=1;i<=n;i++) if(infected[i]) res++;
    cout << res<< endl;
  }
}

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

class Packet {
public:
	int t, s, d;
	bool operator<(Packet p) {
		return t < p.t;
	}
};

signed main() {
	for (int N, M; cin >> N >> M&&N;) {
		vector<char> f(N, false);
		f[0] = true;
		vector<Packet> P(M);
		rep(i, 0, M) {
			cin >> P[i].t >> P[i].s >> P[i].d;
			P[i].s--, P[i].d--;
		}
		sort(P.begin(), P.end());
		rep(i, 0, M) {
			if (f[P[i].s])f[P[i].d] = true;
		}
		int ans = 0;
		rep(i, 0, N) {
			if (f[i])ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

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

typedef long long ll;
typedef struct DATA{
  ll t, s, d;
}data;

data make_d(ll a, ll b, ll c){
  data ret;
  ret.t=a;
  ret.s=b;
  ret.d=c;
  return ret;
}

bool comp(const data &a, const data &b){
  return a.t<b.t;
}

int N, M;
int flag[20001];

int main(){
  while(cin>>N>>M, !(N==0&&M==0)){
    vector<data> v;
    memset(flag, 0, sizeof(flag));
    for(ll i=0; i<M; i++){
      ll tmp1, tmp2, tmp3;
      cin>>tmp1>>tmp2>>tmp3;
      v.push_back(make_d(tmp1, tmp2, tmp3));
    }
    sort(v.begin(), v.end(), comp);
    flag[1]=1;
    ll cnt=1;
    for(ll i=0; i<M; i++)
      if(flag[v[i].s]==1){
	flag[v[i].d]=1;
	cnt++;
      }
    cout<<cnt<<endl;
  }
  return 0;
}

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

#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

int main()
{
    int n, m;
    while (cin >> n >> m, n) {
        vector<int> v(n, 0); 
        v[0] = 1;
        loop(m ,i) {
            int t, s, d;
            cin >> t >> s >> d;
            if (v[s-1] == 1) {
                v[d-1] = 1;
            }
        }
        cout << accumulate(all(v), 0) << endl;
    }
}