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 <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int n, m; 
    while(cin >> n >> m, n || m) {
        int t[100010], s[100010], d[100010];
        int s2[100010], d2[100010];
        map<int, int> mp;
        rep(i,0,m) {
            cin >> t[i] >> s[i] >> d[i];
            mp[t[i]];
        }

        int num = 0;
        for(auto &x : mp) x.sc = num++;
        rep(i,0,m) {
            // printf("t[%lld] = %lld, mp[t[i]] = %lld\n", i, t[i], mp[t[i]]);
            s2[ mp[ t[i] ] ] = s[i];
            d2[ mp[ t[i] ] ] = d[i];
        }

        bool infect[100010] = {};
        infect[1] = true;
        rep(i,0,n) {
            if(infect[ s2[i] ]) {
                infect[ d2[i] ] = true;
            }
        }
        int ans = 0;
        rep(i,0,100000) {
            if(infect[i]) ans++;
        }
        cout << ans << endl;
    }
    return 0;
}

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

struct A{
	int t,s,d;
	A(int t,int s,int d):t(t),s(s),d(d){}
	bool operator<(const A &a)const{return t<a.t;}
};

bool infected[20000];
int main(){
	int n,m;
	while(cin>>n>>m,n||m){
		vector<A> v;
		v.reserve(m);
		memset(infected,false,sizeof(infected));
		infected[0]=true;
		rep(i,m){
			int t,s,d;
			cin>>t>>s>>d;
			v.push_back(A(t,s-1,d-1));
		}
		sort(v.begin(),v.end());
		rep(i,v.size()){
			infected[v[i].d] |= infected[v[i].s];
		}
		cout<<count(infected,infected+n,true)<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;
using P = pair<int, int>;
using namespace std;
 
template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}
 
struct edge {
    int from, to, cost;
    edge(int f, int t, int c) :from(f), to(t), cost(c) {}
};
 
bitset<200001> ans;
 
int main() {
    int n, m;
    while (cin >> n >> m and n) {
        ans.reset();
        vector< pair<int, pair<int, int>> > p;
        rep(i, m) {
            int t, s, d;
            cin >> t >> s >> d;
            s--;
            d--;
            p.push_back(make_pair(t, make_pair(s, d)));
        }
        sort(p.begin(), p.end());
        vector<edge> g[20001];
        ans[0] = 1;
        rep(i, m) {
            pair<int, int> tmp = p[i].second;
            int to = tmp.first, from = tmp.second;
            if (ans[to]) ans[from] = 1;
        }
        cout << ans.count() << endl;
    }
    return 0;
}

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

using namespace std;
typedef pair<int, int> P;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()

int main() {
  while (1) {
    int N, M; cin >> N >> M;
    if (N == 0 and M == 0) break;
    vector<P> packets(N);
    vector<int> S(N), D(N);
    REP(i, M) {
      int t; cin >> t >> S[i] >> D[i]; S[i]--, D[i]--;
      packets[i] = P(t, i);
    }
    sort(ALL(packets));
    vector<bool> infected(N, false);
    infected[0] = true;
    for (P packet : packets) {
      int i = packet.second, s = S[i], d = D[i];
      infected[d] =  infected[d] | infected[s];
    }
    cout << accumulate(ALL(infected), 0) << 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;
}