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 <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int N,M;
vector<pair<int,P> > vec;
bool f[20004];

void solve() {
    rep(i,20004) f[i]=false;
    f[1]=true;
    vec.clear();

    rep(i,M) {
        int t,s,d;
        cin>>t>>s>>d;
        vec.pb(mp(t,mp(s,d)));
    }
    sort(all(vec));

    rep(i,vec.size()) {
        int t=vec[i].fr;
        int s=vec[i].sc.fr;
        int d=vec[i].sc.sc;
        if(f[s]) f[d]=true;
    }
    int ans=0;
    rep(i,20004) if(f[i]) ans++;
    cout<<ans<<endl;

}

int main() {
    while(cin>>N>>M) {
        if(N+M==0) break;
        solve();
    }
    return 0;
}

C++: #include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n,m;
	while(cin>>n>>m,n||m){
		bool infect[n+1];
		rep(i,n+1)infect[i]=false;
		infect[1]=true;
		long long ans=1;
		long long t[m];
		int s[m],d[m];
		rep(i,m)cin>>t[i]>>s[i]>>d[i];
		for(int i=m;i>=0;i--){
			for(int j=0;j<i-1;j++){
				if(t[j]>t[j+1]){
					long long alt=t[j];
					t[j]=t[j+1];
					t[j+1]=alt;
					alt=s[j];
					s[j]=s[j+1];
					s[j+1]=alt;
					alt=d[j];
					d[j]=d[j+1];
					d[j+1]=alt;
				}
			}
		}
		rep(i,m){
			if(infect[s[i]]){
				if(!infect[d[i]])ans++;
				infect[d[i]]=true;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

class C{
  public:
    int a, b, t;
    C(){}
    C(int aa, int bb, int tt) { a = aa; b = bb; t = tt; }
    bool operator < (const C &c) const { return t < c.t; }
};

int main() {
  int N, M;
  while(cin >>N >>M && N && M){
    vector<C> v(M);
    REP(i, M){
      cin >>v[i].t >>v[i].a >>v[i].b;
      --v[i].a; --v[i].b;
    }
    SORT(v);
    vector<bool> f(N, 0);
    f[0] = 1;
    REP(i, M) if(f[v[i].a]) f[v[i].b] = 1;
    int ans = 0;
    REP(i, N) if(f[i]) ++ans;
    cout <<ans <<endl;
  }
  return 0;
}

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

using namespace std;

int main(){
    bool c[20010];
    int n, m;
    while(cin >> n >> m, n+m){
        fill(c, c+20010, false);
        c[1] = true;
        vector<pair<int, pair<int, int>>> p;
        for(int i=0; i < m; i++){
            int t, s, d;
            cin >> t >> s >> d;
            p.push_back(make_pair(t, make_pair(s, d)));
        }
        sort(p.begin(), p.end());
        for(int i=0; i < m; i++){
            if(c[p[i].second.first]){c[p[i].second.second] = true;}
        }
        int ret = 0;
        for(int i=0; i <= n; i++) if(c[i]) ret++;
        cout << ret << endl;
    }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void)
{
	int n, m;
	while (cin >> n >> m, n && m){
		vector < pair <int, int> > data(m);
		pair <int, int> edge[20050];
		for (int i = 0; i < 20050; i++){
			edge[i].first = edge[i].second = -1;
		}
		int t, s, d;
		for (int i = 0; i < m; i++){
			cin >> t >> s >> d;
			data[i].first = t;
			data[i].second = i;
			edge[i].first = s;
			edge[i].second = d;
		}
		sort(data.begin(), data.end());

		bool infect[20050] = {false};
		infect[1] = true;
		for (int i = 0; i < m; i++){
			int from = edge[data[i].second].first;
			int goal = edge[data[i].second].second;
			if (infect[from]){
				infect[goal] = true;
			}
		}

		int ret = 0;
		for (int i = 0; i <= n; i++){
			if (infect[i]) ret++;
		}
		cout << ret << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<algorithm>
#define MAX 20001
using namespace std;

class Data{
public:
  int t,s,d;
  bool operator<(const Data&a)const{
    return t < a.t;
  }
};


int main(){
 
  int n,m;
  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0)break;
    Data data[m];
    bool node[n+1];
    for(int i = 0 ; i < m ; i++){
      cin >> data[i].t >> data[i].s >> data[i].d;
    }
    sort(data,data + m);
    for(int i = 0 ; i < n+1 ; i++)node[i] = false;
    node[1] = true;
    for(int i = 0 ;i < m ; i++){
      if(node[data[i].s])node[data[i].d] = true;
    }

    int cnt = 0 ;
    for(int i = 0 ; i < n+1 ; i++){
      if(node[i])cnt++;
    }
    cout << cnt << endl;
  }  
  return 0;
}