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 <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

struct packet {
	int t, s, d;
	packet(int t = 0, int s = 0, int d = 0):t(t), s(s), d(d) {}

	bool operator<(const packet& p) const {
		return t < p.t;
	}
};

const int MAX = 20001;
bool infected[MAX];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	for(int n, m; cin >> n >> m, n;) {
		vector<packet> packets;
		packets.reserve(m);
		for(int i = 0; i < m; ++i) {
			int t, s, d;
			cin >> t >> s >> d;
			packets.push_back(packet(t, s, d));
		}

		sort(packets.begin(), packets.end());
		memset(infected, false, sizeof(infected));
		infected[1] = true;
		for(int i = 0; i < m; ++i)
			infected[packets[i].d] |= infected[packets[i].s];

		cout << count(infected, infected + MAX, true) << endl;
	}

	return EXIT_SUCCESS;
}

C++: #include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(const T a, const T b){return a>=0 ? a/b : (a+1)/b-1;}
template<class T> T div_ceil(const T a, const T b){return a>=0 ? (a-1)/b+1 : a/b;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
    int n, m;
    while(scanf("%d%d", &n, &m) && n){
        tuple<int, int, int> tp[m];
        rep(i, m){
            int t, s, d;
            scanf("%d%d%d", &t, &s, &d);
            --s; --d;
            tp[i] = make_tuple(t, s, d);
        }
        sort(tp, tp+m);
        int flag[n];
        rep(i, n) flag[i] = 0;
        flag[0] = 1;
        int ans = 1;
        rep(i, m){
            int t, s, d;
            tie(t, s, d) = tp[i];
            if(flag[s]){
                ans += !flag[d];
                flag[d] = 1;
            }
        }
        printf("%d\n", ans);
    }
}

C++: #include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n, m;
        cin >> n >> m;
        if(n == 0)
            return 0;

        vector<bool> infected(n+1, false);
        infected[1] = true;

        vector<pair<int, pair<int, int> > > a(m);
        for(int i=0; i<m; ++i)
            cin >> a[i].first >> a[i].second.first >> a[i].second.second;
        sort(a.begin(), a.end());

        for(int i=0; i<m; ++i){
            int s = a[i].second.first;
            int d = a[i].second.second;
            if(infected[s])
                infected[d] = true;
        }

        int ret = 0;
        for(int i=1; i<=n; ++i){
            if(infected[i])
                ++ ret;
        }
        cout << ret << endl;
    }
}

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

using namespace std;

int main(){
  long long int n,m,i, k;
  while(cin >> n >> m, n != 0 || m != 0) {
    vector<long long int> v(20100,0);
    long long int cnt = 1, data[20100][10] = {};
    long long int in[20100] = {};
    in[1] = 1;
    k = 0;
    for(i = 0; i < m; i++) {
      long long int t,s,g;
      cin >> t >> s >> g;
      data[i][0] = s;
      data[i][1] = g;
      v[k++] = t;
    }
    for(i = 0; i < m - 1; i++) {
      for(int j = m - 1; j > i; j-- ) {
	if(v[i] > v[j]) {
	  swap(v[i], v[j]);
	  swap(data[i], data[j]);
	}
      }
    }
    //    sort(v.begin(), v.begin() + m);
    for(i = 0; i < m; i++) {
      if(in[data[i][0]]){
	  if(in[data[i][1]] == 0)
	    {
	      cnt++;
	      in[data[i][1]] = 1;
	    }
	}
    }
      
    cout << cnt << endl;
  }
  return 0;
}

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

struct packet {
    int t, s, d;

    packet() {}
    ~packet() {}

    packet(int a, int b, int c): t(a), s(b), d(c) {}

    bool operator < (const packet& o) const {
        return t < o.t;
    }
};

int solve(int& N, int& M, vector<packet>& data) {
    sort(begin(data), end(data));
    vector<int> status(N + 1, 0);

    status[1] = 1;

    for(packet& p: data) {
        status[p.d] = max(status[p.d], status[p.s]);
    }

    int ret = 0;
    for(int& v: status) {
        ret += v;
    }

    return ret;
}

int main() {
    int N, M;
    vector<packet> data;
    while(true) {
        cin >> N >> M;
        if(N == 0) break;
        data.resize(M);
        for(packet& d : data) {
            cin >> d.t >> d.s >> d.d;
        }

        cout << solve(N, M, data) << endl;
    }
    return 0;
}