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;

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) {
        ll d = euclid(b, a % b, y, x);
        return y -= a / b * x, d;
    }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1)
            ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1);
        return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e)
            return Mod(1);
        Mod r = *this ^ (e / 2);
        r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);

    for (;;) {
        int n, m;
        cin >> n >> m;

        if (!n) break;

        vector<pair<int, pair<int, int>>> v(m);
        rep(i, 0, m) cin >> v[i].first >> v[i].second.first >> v[i].second.second;

        sort(all(v));

        vector<int> inf(n + 1);
        inf[1] = 1;

        rep(i, 0, m) {
            if (inf[v[i].second.first])
                inf[v[i].second.second] = true;
        }

        int ans = 0;
        rep(i, 1, n + 1) if (inf[i] == 1) ans++;
        cout << ans << endl;
    }
}

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

using namespace std;
typedef pair<int, int> pii;

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

    vector<bool> infect(n, false);
    infect[0] = true;
    for (int i = 0; i < m; i++) {
      int tt = t[i].second;
      infect[d[tt]] = infect[d[tt]] | infect[s[tt]];
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
      ans += infect[i];
    }

    cout << ans << endl;
  }

  return 0;
}

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

class Flow{
public:
    int t,s,d;
    bool operator<(const Flow &f)const{
        return f.t>this->t;
    }
};

int main(){
    int n,m;
    while(cin>>n>>m&&!(n==0&&m==0)){
        vector<Flow> v;
        for(int i = 0; i < m; i++){
            Flow f;
            cin>>f.t>>f.s>>f.d;
            v.push_back(f);
        }
        sort(v.begin(),v.end());
        int p=1;
        for(int i = 0; i < v.size(); i++){
            if(v[i].s==p){
                p=v[i].d;
            }
        }
        cout<<p<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::fixed;
using std::pair;
using std::make_pair;
using std::string;
using std::vector;
using std::list;
using std::map;
using std::set; // insert erase find count
using std::queue;
using std::priority_queue;
using std::stack;
/* c++11
#include <tuple>
using std::tuple; 
using std::make_tuple;
using std::get; // tuple std::get<NUM>(t); (0 <= NUM <= 2)
 */

typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, pair<int, int> > PIII;

void print_pq(priority_queue<PIII> pq) {
    while (!pq.empty()) {
        cout << -pq.top().first << " ";
        cout << pq.top().second.first << " ";
        cout << pq.top().second.second << endl;
        pq.pop();
    }
}

void move(priority_queue<PIII> &table, VI &infected) {
    while (!table.empty()) {
        int from = table.top().second.first;
        int to = table.top().second.second;
        if (infected[from] == 1) {
            infected[to] = 1; 
        }
        table.pop();
    }
    return;
}

int count (VI &infected) {
    int ret = 0; 
    for (int i = 0; i < (int)(infected.size()); i++) {
        if (infected[i] == 1) {
            ret++; 
        }
    }
    return ret;
}

int main(void) {
    int n;
    int m;
    while (1) {
        cin >> n >> m;
        if (n == 0 && m == 0) {
            break;
        }
        priority_queue<PIII> table;
        VI infected(n, false);
        infected[0] = true;
        for (int i = 0; i < m; i++) {
            int t;
            int s;
            int d;
            cin >> t >> s >> d;
            table.push(make_pair(-t, make_pair(s - 1, d - 1))); 
        }
        move(table, infected);
        cout << count(infected) << endl;
    }
    return 0;
}