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;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x)*(x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main() {
    int n, m;
    while (cin >> n >> m, n|m) {
        vector<pair<int, pii>> packets;
        REP(i, m) {
            int t, s, d;
            cin >> t >> s >> d;
            s--;
            d--;
            packets.push_back({t, {s, d}});
        }
        SORT(packets);
        vb infected(n);
        infected[0] = true;
        for (auto pkt : packets) {
            int s = pkt.second.first, d = pkt.second.second;
            if (infected[s]) infected[d] = true;
        }
        int ans = 0;
        REP(i, n) {
            if (infected[i]) ans++;
        }
        cout << ans << endl;
    }
}

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

struct Packet {
    int t, s, d;
};

int main() {
    while (true) {
        int n, m;
        cin >> n >> m;
        if ((n | m) == 0) {
            break;
        }
        vector<Packet> packets(m);
        for (int i = 0; i < m; i++) {
            cin >> packets[i].t >> packets[i].s >> packets[i].d;
        }
        for (int i = 0; i < m - 1; i++) {
            for (int j = 0; j < m  - 1 - i; j++) {
                if (packets[j].t > packets[j + 1].t) {
                    Packet temp = packets[j];
                    packets[j] = packets[j + 1];
                    packets[j + 1] = temp;
                }
            }
        }
        vector<bool> isInfected(n + 1);
        fill(isInfected.begin(), isInfected.end(), false);
        isInfected[1] = true;
        int infectedNum = 1;
        for (int i = 0; i < m; i++) {
            if (isInfected[packets[i].s] == true && isInfected[packets[i].d] == false) {
                isInfected[packets[i].d] = true;
                infectedNum++;
            }
        }
        cout << infectedNum << endl;
    }
}

C++: #include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

int main(void) {
  ll N, M;
  while(cin >> N >> M, N) {
    vector<vector<pll>> E(N);
    REP(i, 0, M) {
      ll t, s, d;
      cin >> t >> s >> d;
      s--;
      d--;
      E[s].push_back(pll(t, d));
    }

    vector<bool> used(N, false);
    priority_queue<pll, vector<pll>, greater<pll>> q;
    q.push(pll(0, 0));
    while(q.size()) {
      ll v = q.top().second, t = q.top().first;
      q.pop();

      if(used[v]) continue;
      used[v] = true;

      for(pll p : E[v]) {
        ll nv = p.second, nt = p.first;
        if(nt >= t) {
          q.push(pll(nt, nv));
        }
      }
    }

    ll ans = 0;
    REP(i, 0, N) if(used[i]) ans++;
    cout << ans << endl;
  }
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<map>
#include<bitset>
#include<vector>

using namespace std;

typedef pair<int,int> P;
typedef pair<int,P> PP;

vector<PP> packets;
bitset<50000> infected;

int main(void) {
    while(1) {
        int n,m;
        cin >> n >> m;
        if(!n) break;

        packets.clear();
        infected.reset();
        infected.set(0);

        for(int i=0; i<m; i++) {
            int t,s,d;
            cin >> t >> s >> d;
            s--;d--;
            packets.push_back(PP(t,P(s,d)));
        }

        sort(begin(packets), end(packets));

        for(auto &pk : packets)
            if(infected[pk.second.first])
                infected.set(pk.second.second);

        cout << infected.count() << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct data{
	int t;
	int s;
	int d;
};

bool operation(const data &l,const data&r){
	return l.t < r.t;
}
int main(){
	bool b[20001];
	int N,M;
	vector<data> v;
	data da;
	int res;
	while(1){
		cin >> N >> M;
		if(N == 0)break;
		v.clear();
		for(int i = 1;i <= N;i++){
			b[i] = false;
		}
		for(int i = 0;i < M;i++){
			cin >> da.t >> da.s >> da.d;
			v.push_back(da);
		}
		sort(v.begin(),v.end(),operation);
		b[1] = true;
		res = 1;
		for(int i = 0;i < v.size();i++){
			if(b[v[i].s] && !b[v[i].d]){
				b[v[i].d] = true;
				res++;
				//cout << v[i].s << " : " << v[i].d <<endl;
			}
		}
		cout << res <<endl;
	}


	return 0;
}

C++: #include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	long long n,m;
	while(cin>>n>>m,n){
		long long a[111]={0},b[111][2]={0},t,s=0;
		a[1]=1;
		r(i,m){
			cin>>t;
			cin>>b[t][0]>>b[t][1];
		}
		r(i,m+1)if(a[b[i][0]])a[b[i][1]]=1;
		r(i,111)if(a[i])s++;
		cout<<s<<endl;
	}
}