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>
#include <algorithm>

using namespace std;

struct data{
	int t;
	int s;
	int d;
	bool operator<( const data& right ) const {
        return t < right.t;
    }
};

int main(void){
//	FILE* fp_in = freopen("data.txt", "r", stdin);
	while(1) {
		int N, M;
		vector< bool > c;
		vector< data > d;
	
		cin >> N >> M;
		if( N == 0 && M == 0 ) break;
	
		for(int i = 0; i < N; i++)
			c.push_back( false );
		c[0] = true;
	
		for(int i = 0; i < M; i++) {
			data newdata;
			cin >> newdata.t >> newdata.s >> newdata.d;
			newdata.s --;
			newdata.d --;
			d.push_back( newdata );
		}
			
		sort( d.begin(), d.end() );

		for(int i = 0; i < d.size(); i++) {
			if ( c[d[i].s] == true ) c[d[i].d] = true;
		}

		int ans = 0;
		for(int i = 0; i < c.size(); i++) {
			if( c[i] == true ) ans ++;
		}
		cout << ans << endl;
	}
//	while(1){}
    return 0;
}

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

using namespace std;

typedef pair<int , pair<int, int> > edge;

int main(){
	int n, m;
	
	while(cin >> n >> m, (n||m)){
		
		vector<edge> vc;
		int t, s, d;
		
		for(int i=0; i<m; ++i){
			
			cin>>t>>s>>d;
			vc.push_back(make_pair(t, make_pair(s, d));
		}
		
		sort(vc.begin(), vc.end());
		set<int> infect;
		infect.insert(1);
		int res = 0;
		for(int i=0; i<m; ++i){
			
			if(infect.count(vc[i].second.first) ^ infect.count(vc[i].second.second)){
				
				infect.insert(vc[i].second.first);
				infect.insert(vc[i].second.second); 
				res++;
			}
		}
		
		cout << res << endl;
	}
	
	return 0;
}

C++: #include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
using namespace std;

struct edge{
    int t,from,to;
    edge(int t,int from,int to):
        t(t),from(from),to(to){}
    edge(){}
    bool operator<(const edge &e)const{
        return t<e.t;
    }
};

int N,M;
vector<edge>es;

void solve(){
    bool flag[20000];
    fill_n(flag,N,false);
    flag[0]=true;
    sort(es.begin(),es.end());

    for(int i=0;i<M;i++){
        edge &e=es[i];
        flag[e.to]|=flag[e.from];
    }

    int ans=0;
    for(int i=0;i<N;i++)if(flag[i])ans++;

    printf("%d\n",ans);
}
int main(){
    while(scanf("%d%d",&N,&M),N||M){
        es.clear();
        for(int i=0;i<M;i++){
            int t,from,to;
            scanf("%d%d%d",&t,&from,&to);
            es.push_back(edge(t,from-1,to-1));
        }

        solve();
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m,n){
    int a,b,c,k[20001]={},s[22222][2];
    k[1]=1;
    for(int i=0;i<m;i++){
      cin>>a>>b>>c;
      s[a][0]=b;
      s[a][1]=c;
    }

    for(int i=1;i<=m;i++){
      if(k[s[i][0]]==1)k[s[i][1]]=1;
    }
    int ans=0;
    for(int i=1;i<=n;i++)ans+=k[i];
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main() {
  int N, M, t, s, d, ans;
  vector< vector<int> > packets;
  while (cin >> N >> M, N) {
    vector<bool> infected(N, false);
    infected[0] = true;
    for (int i = 0; i < M; ++i) {
      cin >> t >> s >> d;
      packets.push_back({t, s-1, d-1});
    }
    sort(packets.begin(), packets.end());
    for (int i = 0; i < M; ++i) {
      s = packets[i][1];
      d = packets[i][2];
      if (infected[s]) infected[d] = true;
    }
    ans = 0;
    for (int i = 0; i < N; ++i) if (infected[i]) ++ans;
    cout << ans << endl;
    packets.erase(packets.begin(), packets.end());
  }
  return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  while (1) {
    int N, M; cin >> N >> M;
    if (N == 0 and M == 0) break;
    vector<T> packets(M);
    REP(i, M) {
      int t, s, d; cin >> t >> s >> d; s--, d--;
      packets[i] = T(t, s, d);
    }
    sort(ALL(packets));
    vector<bool> infected(N, false);
    infected[0] = true;
    for (T packet : packets) {
      int t, s, d; tie(t, s, d) = packet;
      infected[d] =  infected[d] | infected[s];
    }
    cout << accumulate(ALL(infected), 0) << endl;
  }

  return 0;
}