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>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	int n,m;
	while(1){
		cin >> n >> m;
		bool isok[20001];
		REP(i,20001) isok[i] = true;
		isok[0] = false;
		vector<pair<int,pair<int,int> > > sendd;
		if(n==0&&m==0) break;
		REP(i,m){
			int t,s,d;
			cin >> t >> s >> d;
			sendd.pb(mp(t,mp(s,d)));
		}
		sort(All(sendd));
		REP(i,m){
			if(isok[sendd[i].second.first-1]==false) isok[sendd[i].second.second-1] = false;
		}
		ll int cnt = 0;
		REP(i,n){
			if(!isok[i]) cnt++;
		}
		cout << cnt << endl;
		
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
#define t first
#define s second.first 
#define d second.second

int main(){
  vector <pair<int ,pair<int ,int> > > a;


  while(1){
  int n,m;
  int b[20000]={};
  b[1]=1;
  cin>>n>>m;
  if(n==0 && m==0)break;
  a.resize(m);
  for(int i=0;i<m;i++)
    cin>>a[i].t>>a[i].s>>a[i].d;

  sort(a.begin(),a.end());

  int count=1;
  for(int i=0;i<m;i++)
    if(b[a[i].s]==1){
      b[a[i].d]=1;
      count++;
    }
  cout<<count<<endl;
  }

  return 0;
}

C++: #include <cstdio>
using namespace std;

int main(void){
    int N,M,i,t,d,s,cnt;

    while(1){
        scanf("%d",&N);
        scanf("%d",&M);
        if(!N && !M){break;}
        int pcs[N];
        for(i=0;i<N;i++){pcs[i]=0;}
        pcs[0]=1;
        cnt=0;
        for(i=0;i<M;i++){
            scanf("%d",&t);
            scanf("%d",&s);
            scanf("%d",&d);
            if(pcs[s-1]){pcs[d-1]=1;}
        }
        for(i=0;i<N;i++){if(pcs[i]){cnt++;}}
        printf("%d\n",cnt);
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int N, M;
    cin >> N >> M;
    if (N == 0 && M == 0){
      break;
    }
    vector<tuple<int, int, int>> T(M);
    for (int i = 0; i < M; i++){
      int t, s, d;
      cin >> t >> s >> d;
      s--;
      d--;
      T[i] = make_tuple(t, s, d);
    }
    sort(T.begin(), T.end());
    vector<bool> I(N, false);
    I[0] = true;
    for (int i = 0; i < M; i++){
      int s = get<1>(T[i]);
      int d = get<2>(T[i]);
      if (I[s]){
        I[d] = true;
      }
    }
    int ans = 0;
    for (int i = 0; i < N; i++){
      if (I[i]){
        ans++;
      }
    }
    cout << ans << endl;
  }
}

C++: #include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

struct Data {
  int t;
  int f;
  int d;
  Data() {;}
  Data(int t, int f, int d) : t(t), f(f), d(d) {;}
  bool operator<(const Data &rhs) const {
    return t < rhs.t;
  }
};

bool infect[30000];
Data data[30000];

int main() {
  int n, m;
  while (scanf("%d %d", &n, &m), n|m) {
    MEMSET(infect, false);
    REP(i, m) {
      int t, s, d;
      scanf("%d %d %d", &t, &s, &d);
      s--; d--;
      data[i] = Data(t, s, d);
    }
    sort(data, data + m);
    int ans = 1;
    infect[0] = true;
    REP(i, m) {
      if (infect[data[i].f] && !infect[data[i].d]) {
        infect[data[i].d] = true;
        ans++;
      }
    }
    printf("%d\n", ans);
  }
}