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 <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int n, m; 
    while(cin >> n >> m, n || m) {
        int t[100010], s[100010], d[100010];
        int s2[100010], d2[100010];
        memset(s2, -1, sizeof(s2));
        memset(d2, -1, sizeof(d2));
        map<int, int> mp;
        rep(i,0,m) {
            cin >> t[i] >> s[i] >> d[i];
            mp[t[i]];
        }

        int num = 0;
        for(auto &x : mp) x.sc = num++;
        rep(i,0,m) {
            // printf("t[%lld] = %lld, mp[t[i]] = %lld\n", i, t[i], mp[t[i]]);
            s2[ mp[ t[i] ] ] = s[i];
            d2[ mp[ t[i] ] ] = d[i];
        }

        bool infect[100010] = {};
        infect[1] = true;
        rep(i,0,100010) {
            if(s2[i] == -1) continue;
            if(infect[ s2[i] ]) {
                infect[ d2[i] ] = true;
            }
        }
        int ans = 0;
        rep(i,0,100000) {
            if(infect[i]) ans++;
        }
        cout << ans << endl;
    }
    return 0;
}

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

#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

int main()
{
    int n, m;
    while (cin >> n >> m, n) {
        vector<int> v(n, 0); 
        v[0] = 1;
        vector<vector<int>> ps(m);
        loop(m ,i) {
            vector<int> tsd(3);
            cin >> tsd[0] >> tsd[1] >> tsd[2];
            ps[i] = tsd;
        }
        sort(all(ps));
        for(auto p : ps) {
            if(v[p[1]-1] == 1) v[p[2]-1] = 1; 
        }
        cout << accumulate(all(v), 0) << endl;
    }
}

C++: #include <iostream>
#include <algorithm>
#define MAX_N 20000
#define MAX_M 20000
using namespace std;

bool infected[MAX_N + 1];
int t[MAX_M], s[MAX_M], d[MAX_M];

int identify(int n, int m) {
  for (int i = 0; i < m; i++) {
    if (infected[s[i]] == true) infected[d[i]] = true;
  }

  int count = 0;
  for (int i = 1; i <= n; i++) {
    if (infected[i] == true) count++;
  }
  return count;
}

void sort(int n) {
  for (int i = 0; i < n; i++) {
    for (int j = i; j > 0; j--) {
      if (t[j - 1] > t[j]) {
	swap(t[j - 1], t[j]);
	swap(s[j - 1], s[j]);
	swap(d[j - 1], d[j]);
      }
    }
  }
}

void init() {
  for (int i = 0; i < MAX_N + 1; i++)
    infected[i] = false;
  for (int i = 0; i < MAX_M; i++) {
    t[i] = s[i] = d[i] = 0;
  } 
}

int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0) return 0;

    init();
    for (int i = 0; i < m; i++)
      cin >> t[i] >> s[i] >> d[i];
    
    sort(m);
    infected[1] = true;
    int number = identify(n, m);
    cout << number << endl;
  }
}

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

using namespace std;

struct data{
	int t;
	int s;
	int d;
	bool operator<( const data& right ) const {
        return t < right.t;
    }
};

int main(void){
	while(1) {
		int N, M;
		vector< bool > c;
		vector< data > d;
	
		cin >> N >> M;
		if( N == 0 && M == 0 ) break;
	
		for(int i = 0; i < N; i++)
			c.push_back( false );
		c[0] = true;
	
		for(int i = 0; i < M; i++) {
			data newdata;
			cin >> newdata.t >> newdata.s >> newdata.d;
			newdata.s --;
			newdata.d --;
			d.push_back( newdata );
		}
			
		sort( d.begin(), d.end() );

		for(int i = 0; i < d.size(); i++) {
			cout << d[i].t << " " << d[i].s << " " << d[i].d << endl;
			if ( c[d[i].s] == true ) c[d[i].d] = true;
		}

		int ans = 0;
		for(int i = 0; i < c.size(); i++) {
			if( c[i] == true ) ans ++;
		}
		cout << ans << endl;
	}
    return 0;
}