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 <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, pair<int,int> > pii;

int main(){
  int N, M, t, s, d;
  while(scanf("%d%d", &N, &M) && N+M){
    vector<pii>v(M);
    rep(i, M){
      scanf("%d%d%d", &t, &s, &d);
      s--; d--;
      v[i] = make_pair(t, make_pair(s, d));
    }

    sort(v.begin(), v.end());
    vector<bool>f(N, 0);
    f[0] = 1;
    rep(i, M){
      int a = v[i].S.F; int b = v[i].S.S;
      if(f[a]) f[b] = 1;
    }
    int res = 0;
    rep(i, N) if(f[i]) res++;
    //    printf("%d %d %d\n", (int)f[0], (int)f[1], (int)f[2]);
    printf("%d\n", res);
  }
  return 0;
}

C++: 
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cassert>
#include <iomanip>

using namespace std;

#define pb push_back
typedef long long ll;
typedef complex<int> P;

struct st{
	ll t;
	int s;
	int d;
	
	st(){}
	st(ll t,int s,int d): t(t), s(s), d(d){}
	
	bool operator< (const st &s) const{
		return this->t < s.t;
	}
};

bool solve(){
	int n, m;
	cin>> n>> m;
	if(n==0 && m==0) return false;
	
	vector<st> vst;
	for(int i=0;i<m;i++){
		ll t; int s, d;
		cin>> t>> s>> d;
		vst.pb(st(t, s-1, d-1));
	}
	sort(vst.begin(), vst.end());
	
	vector<bool> com(n);
	fill(com.begin(), com.end(), false);
	com[0] = true;
	for(int i=0;i<m;i++){
		if(com[vst[i].s]) com[vst[i].d] = true;
	}
	
	cout<< count(com.begin(), com.end(), true)<< endl;
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	
	while(solve());

	return 0;
}

C++: #include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	long long n,m;
	while(cin>>n>>m,n){
		vector<pair<int,pair<int,int> > >v;
		pair<int,pair<int,int> >p;
		long long a[20001]={0},t,s=0;
		a[1]=1;
		r(i,m){
			cin>>p.first>>p.second.first>>p.second.second;
			v.pushback(p);
		}
		sort(v.begin(),v.end());
		r(i,m)if(a[v[i].second.first])a[v[i].second.second]=1;
		r(i,n+1)if(a[i])s++;
		cout<<s<<endl;
	}
}

C++: #include <cstdio>
#include <utility>
#include <cctype>
#include <vector>
#include <algorithm>
using namespace std;

#ifdef __linux
#define _U(s) s##_unlocked
#else
#define _U(s) _##s##_nolock
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
#define gcu _U(getchar)
#define pcu _U(putchar)
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;char c;while(isspace(c = gcu()));do{s+=c;}while(c=gcu(),c!=' '&&c!='\n'&&c!=EOF);return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;while(isspace(c = gcu()));if(c=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
	_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
	_HT _OUT(H &&h, T... t){out(h);out(t...);}
	template <typename... T> _OUTL(T... t){out(t...);outl();}
	struct range{
		int e,b=0,s=1;range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
		struct it{int v,s; it(int _v,int _s):v(_v),s(_s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
			it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i,n) for(int i=n;i;i--)

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

int main() {
	for (int N, M; N = in, M = in, M || N;) {
		vector<P> p(M);
		vector<bool> c(N);
		c[0] = true;
		for (P &i: p)
			i = {in, (int) in - 1, (int) in - 1};
		sort(begin(p), end(p), [](P a, P b){return a.t < b.t;});
		for (P &i: p)
			c[i.d] = c[i.d] | c[i.s];
		outl(count(begin(c), end(c), true));
	}
}