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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


struct Packet
{
	int t, s, d;
	bool operator<(const Packet& obj) const
	{
		return t < obj.t;
	}
};
int main()
{
	ios::sync_with_stdio(false);

	int n, m;
	while (cin >> n >> m, n)
	{
		bool infe[22222];
		fill(infe, infe + (n + 1), false);
		infe[1] = true;

		Packet p[22222];
		for (int i = 0; i < m; ++i)
			cin >> p[i].t >> p[i].s >> p[i].d;
		sort(p, p + m);
		for (int i = 0; i < m; ++i)
			if (infe[p[i].s])
				infe[p[i].d] = true;
		cout << count(infe, infe + (n + 1), true) << endl;
	}
}

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

using namespace std;

#define MAX 20000

struct edge{
  int to, cost;

  edge(int to = -1, int cost = -1) : to(to), cost(cost) {}
};

int ans, N;
edge e[MAX];

void solve(int p, int c){
  if(e[p].to != -1 && e[p].cost > c){
    ans++;
    solve(e[p].to, c+1);
  }
}

int main(){
  int M, t, s, d;

  while(cin >> N >> M , N){
    for(int i = 0 ; i < N ; i++){
      e[i] = edge();
    }

    for(int i = 0 ; i < M ; i++){
      cin >> t >> s >> d;
      e[s-1] = edge(d-1, t);
    }

    ans = 1;
    solve(0,0);
    cout << ans << endl;
  }

  return 0;
}

C++: #include <iostream>
using namespace std;
struct set{
  int t;
  int s;
  int d;
};
int main(){
  int n,m,i,j,cnt,source,destination,start,end[20001],flag;
  struct set data[20001];
  while(1){
    flag=0;
    for(i=1;i<20001;i++) end[i]=0;
    end[1]=1;
    cin >> n >> m;
    if(n==0&&m==0) break;
    if(m!=0){
      for(i=0;i<m;i++){
	cin >> data[i].t >> data[i].s >> data[i].d;
      }
      for(i=0;i<m;i++){
	for(j=1;j<m;j++){
	  if(data[i].t<data[i-1].t) swap(data[i],data[i-1]);
	}
      }
      for(i=0;i<m;i++){
	if(data[i].s==1||data[i].d==1){
	  source=data[i].s;
	  destination=data[i].d;
	  start=i+1;
	  flag=1;
	  break;
	}
      }
      if(flag==1){
	if(source==1){
	  end[data[i].d]=1;
	  cnt=2;
	}
	if(destination==1) cnt=1;
	for(i=start;i<m;i++){
	  if(end[data[i].s]==1&&end[data[i].d]==0){
	    cnt++;
	    end[data[i].d]=1;
	  }
	}
	cout << cnt << endl;
      }
      else cout << 1 << endl;
    }
    else cout << 0 << endl;
  }
  
  return 0;
}

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];
        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,n) {
            if(infect[ s2[i] ]) {
                infect[ d2[i] ] = true;
            }
        }
        int ans = 0;
        rep(i,0,100000) {
            if(infect[i]) ans++;
        }
        cout << ans << endl;
    }
    return 0;
}