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 <bits/stdc++.h>
#define rep( i, begin, end ) for( int i = begin; i < end; i++ )
using namespace std;
 
int main() {
    int n, m, answer;
    bool infected[20000];
    pair< int, pair < int, int > > packet[20000];
    while( cin >> n >> m, n ) {
        memset( infected, false, sizeof( infected ) );
        infected[ 0 ] = true;
        rep( i, 0, m ) {
            int t, s, d;
            cin >> t >> s >> d;
            packet[ i ] = make_pair( t, make_pair( s, d ) );
        }
        sort( packet, packet + m );
        rep( i, 0, m ) {
            int a, b;
            a = packet[ i ].second.first - 1;
            b = packet[ i ].second.second - 1;
            if( infected[ a ] ) 
                infected[ b ] = true;
        }
        answer = 0;
        rep( i, 0, n ) {
            answer += infected[ i ];
        }
        cout << answer << 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

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) {}
  bool operator<(logs &x)const{
    if(t < x.t) return true;
    return false;
  }
};

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

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

using namespace std;

#define MAX 20000

struct edge{
  int to;

  edge(int to = -1) : to(to) {}
};

int ans, N;
edge e[MAX];

void solve(int p){
  if(e[p].to != -1){
    ans++;
    solve(e[p].to);
  }
}

int main(){
  int M, t, s, d;

  while(cin >> N >> M , N){
    for(int i = 0 ; i < N ; i++){
      e[i] = edge();
    }

    for(int i = 0 ; i < M ; i++){
      cin >> t >> s >> d;
      e[s-1] = edge(d-1);
    }

    ans = 1;
    solve(0);
    cout << ans << endl;
  }

  return 0;
}

C++: 
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2155

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

struct Packet
{
	int time;
	int source;
	int dest;

	Packet(int t, int s, int d): time(t),source(s),dest(d){}
	
	bool operator<( const Packet& right ) const {
		return time < right.time;
	}
};

int main()
{
	int M,N;

	while(cin >> N >> M && N)
	{
		vector< Packet > packets;
		vector<int> PC( N, 0 ); 
		
		int T,S,D;
		rep(nth,M)
		{
			cin >> T >> S >> D;
			packets.push_back( Packet(T,S-1,D-1) );
		}

		sort(ALL(packets));

		
		PC[0] = 1;
		rep(i,M)
		{
			Packet p =  packets[i];
			if(PC[p.source]){ PC[p.dest] = PC[p.source]; }
		}

		int ans = accumulate(ALL(PC),0);
		cout << ans << endl;
	}
	return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct P{
	int t;
	int s;
	int d;
};

int cmp(const void *a,const void *b){
	struct P tmp1 = *(struct P *)a;
	struct P tmp2 = *(struct P *)b;
	return tmp1.t - tmp2.t;
}

int main(void){
	int n, m, count, i, j, p[20000];
	struct P data[20000];
	while(1){
		scanf("%d%d",&n,&m);
		if(n == 0 && m == 0)
			break;
		memset(p,0,sizeof(p));
		p[0] = 1;
		for(i = 0;i < m;i++)
			scanf("%d%d%d",&data[i].t,&data[i].s,&data[i].d);
		qsort(data,m,sizeof(data),cmp);
		for(i = 0;i < m;i++)
			p[data[i].d - 1] += p[data[i].s - 1];
		count = 0;
		for(i = 0;i < n;i++)
			if(p[i]) count++;
		printf("%d\n",count);
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;

const int SZ = 20010;
pair<int, P> data[SZ];
bool infected[SZ];

int main(){
  int N, M;
  while(cin >> N >> M && (N + M) > 0){
    memset(infected, 0, sizeof(infected));

    int count = 1;
    infected[1] = true;
    
    REP(i, M){
      cin  >> data[i].first >> data[i].second.first >> data[i].second.second;
    }
    sort(data, data + M);
    
    REP(i, M){
      int s = data[i].second.first;
      int d = data[i].second.second;
      
      if(infected[s] && !infected[d]){
        count++;
        infected[d] = true;
      }
    }
    cout << count << endl;
  }
  return 0;
  
}