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 <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;

inline bool cheak(ll x, ll y, ll xMax, ll yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline ll toInt(string s) { ll v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }

#define For(i,a,b)	for(ll (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define rFor(i,a,b)	for(ll (i) = (a-1);i >= (b);(i)--)
#define rrep(i,n)	rFor(i,n,0)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))

const ll dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };
const ll mod = 1e9 + 7;
const ll INF = 1e9 + 9;

int main(){

	int n, m;

	while (cin >> n >> m && n){
		vector<T> vec(m);
		vector<bool> inv(n+1, false);
		inv[1] = true;
		rep(i, m){
			cin >> get<0>(vec[i]) >> get<1>(vec[i]) >> get<2>(vec[i]);
		}
		sort(all(vec));
		rep(i, m){
			int s = get<1>(vec[i]), t = get<2>(vec[i]);
			if (inv[s])inv[t] = inv[s];
		}
		int ans = 0;
		rep(i, inv.size()){
			if (inv[i])ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstring>
#include <algorithm>
#include <utility>
#include <vector>
using namespace std;

vector<pair<int, pair<int , int> > > l;

int v[20010];
int n, m, ans;


int main(void){
	int i;
	pair<int, pair<int, int> > p;
	while( cin >> n >> m, n){
		ans = 0;
		l.clear();
		memset(v, 0, sizeof(v));
		for(i = 0; i < m; i++){
			cin >> p.first >> p.second.first >> p.second.second;
			l.push_back(p);
		}
		sort(l.begin(), l.end());
		v[1] = 1;
		for(i = 0; i < m; i++) if(v[l[i].second.first]) v[l[i].second.second] = 1;
		for(i = 1; i <= n; i++) if(v[i]) ans++;
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

class Info {
public:
	int t, s, d;

	bool operator < (const Info& obj) const
	{
		return t < obj.t;
	}
};

int main()
{
	while (true) {
		int n, m;

		cin >> n >> m;

		if (n == 0 && m == 0) {
			break;
		}

		vector<Info> data(m);
		vector<bool> infected(n, false);

		infected[0] = true;

		rep(i, m) {
			cin >> data[i].t >> data[i].s >> data[i].d;
			data[i].s--;
			data[i].d--;
		}

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

		rep(i, m) {
			if (infected[data[i].s] == true) {
				infected[data[i].d] = true;
			}
		}
		
		int ans = 0;

		rep(i, n) {
			if (infected[i] == true) {
				ans++;
			}
		}

		cout << ans << endl;
	}

	return 0;
}

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

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
typedef long long ll;

int main()
{
    int n,m;
    while(cin >> n >> m) {
        if(n == 0 && m == 0) break;
        
        vector<pair<int,pair<int,int> > > v(m);
        rep(i,m) cin >> v[i].first >> v[i].second.first >> v[i].second.second;

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

        int ans = 1;

        bool T[20005];
        memset(T,0,sizeof(T));
        T[1] = true;

        vector<int> id;

        rep(i,m) {
            int time = v[i].first;
            int s = v[i].second.first;
            int t = v[i].second.second;

            if(T[s]) {
                T[t] = true;
            }
        }

        int cnt = 0;
        REP(i,1,n+1) {
            if(T[i]) cnt++;
        }

        cout << cnt << endl;
    }

    return 0;
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, P> PP;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  while(cin>>N>>M,N||M) {
    vector<PP> data(M);
    bool vir[N+1]; CLR(vir);
    vir[1] = true;
    FOR(i,0,M) {
      ll t;
      int s, d;
      cin >> t >> s >> d;
      data[i] = PP(t, P(s, d));
    }
    sort(data.begin(), data.end());
    FOR(i,0,M) {
      if(vir[data[i].second.first]) {
        vir[data[i].second.second] = true;
      }
    }
    int ans = 0;
    FOR(i,1,N+1) {
      ans += vir[i];
    }
    cout << ans << endl;
  }
  return 0;
}