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>
using namespace std;
struct edge{
  int t;
  int from;
  int to;
  edge(){};
  edge(int t,int from,int to):t(t),from(from),to(to){};
  bool operator<(const edge& other) const {
	return t < other.t;
  }
};

int main(){
  int n,m;
  while(cin >> n >> m && n != 0){
	vector<edge> vec;
	for(int i = 0;i < m;i++){
	  int t,f,to;
	  cin >> t >> f >> to;
	  vec.emplace_back(t,f,to);
	}
	sort(vec.begin(),vec.end());
	vector<bool> infected(n,false);
	infected[0] = true;
	for(int i = 0;i < m;i++){
	  int to,from;
	  to = vec[i].to;
	  from = vec[i].from;
	  if(infected[from-1])infected[to-1] = true;
	}
	int res = 0;
	for(int i = 0;i < n;i++){
	  if(infected[i])res++;
	}
	cout << res << endl;
	
  }

  return 0;
}

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

using namespace std;

int main()
{
    long n,m;
    while(cin>>n>>m,n){
        vector<vector<long long> > data(m,vector<long long>(3));
        for(long i=0;i<m;i++) cin>>data[i][0]>>data[i][1]>>data[i][2];
        
        sort(data.begin(),data.end());
        
        set<long long> inf;
        inf.insert(1);
        
        for(int i=0;i<m;i++){
            if(inf.find(data[i][1]) != inf.end() ){
                inf.insert(data[i][2]);
            }
        }
        cout<<inf.size()<<endl;
    }
    
    return 0;
}

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

struct data{int s,d;};

int main()
{
  map<int,data> m;
  map<int,data>::iterator it;
  vector<int> v;
  int N,M,t,s,d;
  int i,cnt;
  data p;
  while(cin>>N>>M,N|M){
    m.clear();
    for(i=0;i<M;i++){
      cin>>t>>s>>d;
      p.s=s;
      p.d=d;
      m[t]=p;
    }
    v.clear();
    v.resize(N+1);
    v[1]=1;
    cnt=1;
    for(it=m.begin();it!=m.end();it++){
      if(v[((*it).second).s]){
	if(!v[((*it).second).d])cnt++;
	v[((*it).second).d]=1;
      }
    }
    cout<<cnt<<endl;
  }
}

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

#define REP(i,a,b) for(i=a; i<b; ++i)
#define rep(i,n) REP(i,0,n)
#define pii pair<int, pair<int,int> >

int main() {
int N,M,t,s,d,i;
  while(cin>>N>>M, N|M) {
    vector<pii > v;
    vector<int> infected(N,0);
    infected[0] = 1;
    rep(i,M) {
      cin>>t>>s>>d;
      v.push_back(pii(t, pair<int,int>(s-1,d-1)));
    }
    sort(v.begin(), v.end());
    rep(i,M) {
      int ts = v[i].second.first,td = v[i].second.second;
      if(infected[ts] && !infected[td] && infected[ts] <= v[i].first)
	infected[td] = v[i].first+1;
    }
    int ans = 0;
    rep(i,N) {
      if(infected[i]) ans++;
    }
    cout<<ans<<endl;
  }
}

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

using namespace std;

struct send
{
	int s;
	int d;
};

int main(void)
{
	int n,m;
	int i1;
	int t;
	int count;

	while(1){
		cin>>n>>m;
		if(n+m==0) break;

		map<int,send> data;
		send sd;
		vector<int> infe(n+1,0);
		infe[1]=1;
		count=1;

		for(i1=0;i1<m;i1++){
			cin>>t>>sd.s>>sd.d;
			data[t]=sd;
		}

		for(map<int,send >::iterator it=data.begin(); it!=data.end();it++){
			if(infe[(*it).second.s]==1) {
				count++;
				infe[(*it).second.d]=1;
			}
		}
		cout<<count<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<queue>

using namespace std;

#define INF 999999999
#define REP(i,n) for(int i=0; i<(int)(n); i++)

struct pac{
	int t, s, d;
	bool operator<(const pac& a) const{
		if(a.t != t) return t < a.t;
	}
};

int main(){
	int n, m, v[20001], t,s,d;
	int ans;
	vector<pac> rec;
	pac in;
	while(1){
		cin >> n >> m;
		if(!n) break;
		REP(i,n+1) v[i] = 0;
		v[1] = 1;
		rec.clear();
		REP(i,m){
			cin >> in.t >> in.s >> in.d;
			rec.push_back(in);
		}
		sort(rec.begin(), rec.begin()+m);
		REP(i,m){
			if(v[rec[i].s]) v[rec[i].d] = 1;
		}
		ans =0;
		REP(i,n+1){
			if(v[i]) ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

#define NMAX 20000
int main(){

	int N,M;
	bool comp[NMAX+1];
	int t,s,d;
	int ans=0;

	while(1){

		cin>>N>>M;
		if(N==0&&M==0) break;

		comp[1]=true;
		for(int i=2;i<=N;i++) comp[i]=false;

		while(M --> 0){
			cin>>t>>s>>d;
			if(comp[s]==true) comp[d]=true;
		}

		ans=0;
		for(int i=1;i<=N;i++){
			if(comp[i]==true) ans++;
		}

		cout<<ans<<endl;
	}

	return 0;
}

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

#define f first
#define s second
#define rep(i, n) for(int i = 0 ; i < n ; i++)

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, P> PP;

int main(){
  int N, M;
  while(cin >> N >> M, N|M){
    vector<PP> v(M);
    rep(i, M) cin >> v[i].f >> v[i].s.f >> v[i].s.s;
    
    sort(v.begin(), v.end());
    
    bool infected[20010];
    memset(infected, false, sizeof(infected));
    infected[1] = true;
    
    rep(i, M){
      int from, to;
      from = v[i].s.f, to = v[i].s.s;
      if(infected[from]) infected[to] = true;
    }
    
    int ans = 0;
    
    for(int i = 1 ; i <= N ; i++){
      if(infected[i]) ans++;
    }
    cout << ans << endl;

  }
  return 0;
}