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
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline long toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline long toLong(string s) {long v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-20;
const long double INF = 1e18;

#define MAX_N 20001
int par[MAX_N];
int rank[MAX_N];

void init(int n){
	REP(i,n){
		par[i]=i;
		rank[i]=0;
	}
}

int find(int x){
	if(par[x]==x){
		return x;
	}else{
		return par[x]=find(par[x]);
	}
}

void unite(int x,int y){
	x=find(x);
	y=find(y);
	if(x==y)return;
	if(rank[x]<rank[y]){
		par[x]=y;
	}else{
		par[y]=x;
		if(rank[x]==rank[y]) rank[x]++;
	}
}

bool same(int x,int y){
	return find(x)==find(y);
}

int main(){
	int N,M;
	while(cin>>N>>M&&N){
		vector<pair<long,PII> >pi;
		REP(i,M){
			long t;
			int s,d;
			cin>>t>>s>>d;
			pi.PB(MP(t,MP(s,d)));
		}
		SORT(pi);
		int res=1;
		init(N+1);unite(0,1);
		REP(i,SZ(pi)){
			if(same(pi[i].second.first,0)&&!same(pi[i].second.second,0)){
				res++;
				unite(pi[i].second.second,0);
			}
		}
		cout<<res<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define REP(i,n)for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ll long long
using namespace std;
int main(){
    int n,m;
    int t[20020],s[20020],d[20020];
    while(1){
        cin>>n>>m;
        if(n==0&&m==0)break;
        vector<pair<int,int> >V;
        REP(i,m){
            cin>>t[i]>>s[i]>>d[i];s[i]--;d[i]--;
            V.PB(MP(t[i],i));
        }
        bool infect[20020];
        memset(infect,false,sizeof(infect));
        infect[0]=true;
        sort(ALL(V));
        REP(i,V.size()){
            int sn=s[V[i].second],dn=d[V[i].second];
            if(infect[sn])infect[dn]=true;
        }
        int ans=0;
        REP(i,n){
            if(infect[i])ans++;
        }
        cout<<ans<<endl;
    }
}

C++: #include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;
  while(cin>>n>>m,n+m){
    vector<pair<ll,pair<ll,ll>>>pll(m);
    for(int i=0;i<m;i++){
      ll t,f,to;
      cin>>t>>f>>to;
      pll[i]=(mp(t,mp(f-1,to-1)));
    }
    sort(ALL(pll));
    vector<bool> virus(n,false);
    virus[0] = true;
    for(int i=0;i<m;i++){
      ll f = pll[i].S.F;
      ll t = pll[i].S.S;
      if(virus[f])virus[t] = true;
    }
    ll ans=0;
    for(auto a:virus)ans+=a;
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
struct edge{
  int t;
  int from;
  int to;
  edge(){};
  edge(int t,int from,int to):t(t),from(from),to(to){};
  bool operator<(const edge& other) const {
	return t < other.t;
  }
};

int main(){
  int n,m;
  while(cin >> n >> m && n != 0){
	vector<edge> vec;
	for(int i = 0;i < m;i++){
	  int t,f,to;
	  cin >> t >> f >> to;
	  vec.emplace_back(t,f,to);
	}
	sort(vec.begin(),vec.end());
	vector<bool> infected(n,false);
	infected[0] = true;
	for(int i = 0;i < m;i++){
	  int to,from;
	  to = vec[i].to;
	  from = vec[i].from;
	  if(infected[from-1])infected[to-1] = true;
	}
	int res = 0;
	for(int i = 0;i < n;i++){
	  if(infected[i])res++;
	}
	cout << res << endl;
	
  }

  return 0;
}