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 <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, m;
    while(cin >> n >> m, n|m){
        vector<int> v(n);
        v[0] = 1;
        vector<array<int, 3>> p(m);
        for (int i = 0; i < m; ++i) {
            for (int j = 0; j < 3; ++j) {
                scanf("%d", &p[i][j]);
            }
        }
        sort(p.begin(),p.end());
        for (int i = 0; i < m; ++i) {
            v[p[i][2]-1] |= v[p[i][1]-1];
        }
        cout << count(v.begin(),v.end(), 1) << "\n";
    }
    return 0;
}

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

class data {
public:
	int t, from, to;
	data(int t, int from, int to) : t(t), from(from), to(to) {}
	bool operator<(const data& d) const {
		return t<d.t;
	}
};

int main()
{
	int N, M;
	while (cin >> N >> M, N||M)
	{
		bool infected[20001] = {0};
		infected[1] = true;
		set<data> dt;

		for (int i=0; i<M; i++)
		{
			int t, s, d;
			cin >> t >> s >> d;
			dt.insert(data(t, s, d));
		}

		for (set<data>::iterator i=dt.begin(); i!=dt.end(); i++)
		{
			if (infected[i->from])
				infected[i->to] = true;
		}

		int cnt = 0;
		for (int i=1; i<=N; i++)
			if (infected[i]) cnt++;

		cout << cnt << endl;

	}
	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)


typedef long long int ll;
typedef double D;      // ??§?¨?????????????double???long double?????????
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;


const int INF = (1<<30) - 1;
const D EPS = 1e-9;

#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)


//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.precision(16);
    
    int N, M;
    while(cin>>N>>M, N|M){
        set<int> infected = {1};
        
        vector<tuple<int, int, int>> packets;
        for(int i=0; i<M; i++){
            int t, s, d; cin >> t >> s >> d;
            packets.push_back({t, s, d});
        }
        sort(packets.begin(), packets.end());
        for(int i=0; i<M; i++){
            int t, s, d; tie(t, s, d) = packets[i];
            if(infected.count(s))
                infected.insert(d);
        }
        
        cout << infected.size() << endl;
    }
    
    return 0;
}

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

using namespace std;

typedef pair<int, int> P;
typedef pair<long long int, P> Q;

int main() {
	int n, m;
	while (cin >> n >> m) {
		if (n == 0 && m == 0) {
			break;
		}
		vector<int> d(n, 0);
		d[0] = 1;
		long long int t;
		int s, D;
		vector<Q> dd;
		for (int i = 0; i < m; i++) {
			cin >> t >> s >> D;
			s--;
			D--;
			dd.push_back(Q(t, P(s, D)));
		}
		sort(dd.begin(), dd.end());
		for (int i = 0; i < m; i++) {
			if (d[(dd[i].second).first] == 1) {
				d[(dd[i].second).second] = 1;
			}
		}
		int MM = 0;
		for (int i = 0; i < n; i++) {
			MM += d[i];
		}
		cout << MM << endl;
	}
	return 0;
}