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 "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2155>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
int N,M;
ll solve(){
    ll res = 0;
    using Items = tuple<int,int,int>;
    vector<Items> com(M);
    for(int i = 0; i < M;i++){
        int t,s,d; cin >> t >> s >> d;
        com[i] = Items(t,s,d);
    }
    sort(com.begin(),com.end());
    vector<int> infected(N+1,0); infected[1] = true;
    for(int i = 0; i < M;i++){
        infected[get<2>(com[i])] |= infected[get<1>(com[i])];
    }
    res = accumulate(infected.begin(),infected.end(),0LL);
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    while(cin >> N >> M,N|M){
        cout << solve() << endl;
    }
    return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  while(1) {
    int n, m;cin >> n >> m;
    if(n == 0 && m == 0) break;
    vector<pair<int, P>> p(m);
    REP(i, m) {
      cin >> p[i].fi >> p[i].se.fi >> p[i].se.se;
    }
    sort(ALL(p));
    vector<bool> infected(n+1, false);
    infected[1] = true;
    REP(i, m) {
      if(infected[p[i].se.fi]) infected[p[i].se.se] = true;
    }
    int ans = 0;
    REP(i, n+1) {
      ans += infected[i];
    }
    cout << ans << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;

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

int main()
{
	int n, m;
	while (scanf("%d %d", &n, &m), n + m){
		bool f[20000] = {true};
		priority_queue<DATA> pq;
		
		for (int i = 0; i < m; i++){
			int t, s, d;
			cin >> t >> s >> d;
			s--; d--;
			pq.push({t, s, d});
		}
		
		for (; pq.size(); pq.pop()){
			DATA data = pq.top();
			f[data.d] |= f[data.s];
		}
		
		int res = 0;
		for (int i = 0; i < n; i++){
			res += f[i];
		}
		
		cout << res << endl;
	}
	
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y) (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)
#define dump3(x, y, z) (cout << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", "<< z << ")" << endl)

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

int N, M;

#define MAX 20010
int dp[MAX];

int main(void)
{
	while (cin >> N >> M, N|M) {
		memset(dp, 0, sizeof(dp));
		dp[0] = 1;
		rep(i, M) {
			int t, s, d;
			cin >> t >> s >> d;
			s--, d--;
			dp[d] |= dp[s];
		}
		int ans = 0;
		rep(i, N)
			ans += dp[i];
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

#define MAX 20000

int ans, N;
bool G[MAX][MAX];

void solve(int p){
  for(int i = 0 ; i < N ; i++){
    if(G[p][i]){
      ans++;
      solve(i);
    }
  }
}

int main(){
  int M, t, s, d;

  while(cin >> N >> M , N){
    memset(G, false, sizeof(G));
    for(int i = 0 ; i < M ; i++){
      cin >> t >> s >> d;
      G[s-1][d-1] = true;
    }

    ans = 1;
    solve(0);
    cout << ans << endl;
  }

  return 0;
}