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 <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <iomanip>
  
using namespace std;

int main()
{
	int n, m;
	while(1){
		cin >> n >> m;
		if(n == 0 && m == 0) break;
		bool isinfected[20000];
		for(int i = 0; i < n; i++){
			if(i == 0) isinfected[i] = true;
			else isinfected[i] = false;
		}
		vector<pair<int, pair<int, int> > > records(20000);
		int t, s, d;
		for(int i = 0; i < m; i++){
			cin >> t >> s >> d;
			records[i].first = t;
			(records[i].second).first = s;
			(records[i].second).second = d;
		}
		sort(records.begin(), records.begin() + m);
		int ans = 1;
		for(int i = 0; i < m; i++){
			int sender = (records[i].second).first - 1;
			int receiver = (records[i].second).second - 1;
			if(isinfected[sender] && !isinfected[receiver]){
				isinfected[receiver] = true;
				ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  int n,m;
  while((n = getInt()) + (m = getInt())){
    vector<bool> inf(n, false);
    vector<pair<int,pair<int,int> > > data(m);

    inf[0] = true;

    REP(i,m){
      data[i].f   = getInt();
      data[i].s.f = getInt() - 1;
      data[i].s.s = getInt() - 1;
    }

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

    REP(i,m){
      int s = data[i].s.f;
      int d = data[i].s.s;

      if(inf[s]) inf[d] = true;
    }

    int ans = 0;
    REP(i,n) if(inf[i]) ++ans;

    print(ans);
  }
  return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 20000;
const int MAX_M = 20000;

/* typedef */

struct Pkt {
  int t, s, d;
  Pkt() {}
  Pkt(int _t, int _s, int _d): t(_t), s(_s), d(_d) {}
  bool operator<(const Pkt& p0) const { return t < p0.t; }
};

/* global variables */

int n, m;
Pkt pkts[MAX_M];
bool ifcts[MAX_N];

/* subroutines */

/* main */

int main() {
  for (;;) {
    cin >> n >> m;
    if (n == 0) break;

    for (int i = 0; i < m; i++) {
      cin >> pkts[i].t >> pkts[i].s >> pkts[i].d;
      pkts[i].s--;
      pkts[i].d--;
    }

    sort(pkts, pkts + m);
    
    memset(ifcts, false, sizeof(ifcts));
    ifcts[0] = true;

    int nifct = 1;
    
    for (int i = 0; i < m; i++) {
      Pkt& pi = pkts[i];
      if (ifcts[pi.s] && ! ifcts[pi.d]) {
	ifcts[pi.d] = true;
	nifct++;
      }
    }

    cout << nifct << 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 if(infected[data[i].d]) infected[data[i].f] = false;
    }
    int res = 0;
    REP(i, n) if(infected[i]) res++;
    cout << res << endl;
  }
}

C++: #include<iostream>
#include<set>

using namespace std;

#define NMAX 20000
#define MMAX 20000

struct S{
	int t,s,d;
};

bool operator<(S a,S b){
	return a.t<b.t;
}

int main(){

	int N,M;
	bool comp[NMAX+1];
	int t,s,d;
	set<S> p;
	S pp;
	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;

		for(int i=0;i<M;i++){
			cin>>t>>s>>d;
			pp.t=t,pp.s=s,pp.d=d;
			p.insert(pp);
		}

		set<S>::iterator it=p.begin();
		while(it!=p.end()){
			//cout<<(*it).t<<","<<(*it).s<<","<<(*it).d<<endl;
			if(comp[(*it).s]==true) comp[(*it).d]=true;
			it++;
		}

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

		cout<<ans<<endl;
		p.clear();
	}

	return 0;
}