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 <stdio.h>
#include <stdlib.h>
#include <string.h>

struct P{
	int t;
	int s;
	int d;
};

int cmp(const void *a,const void *b){
	struct P tmp1 = *(struct P *)a;
	struct P tmp2 = *(struct P *)b;
	return tmp1.t - tmp2.t;
}

int main(void){
	int n, m, count, i, j, p[20000];
	struct P data[20000];
	while(1){
		scanf("%d%d",&n,&m);
		if(n == 0 && m == 0)
			break;
		memset(p,0,sizeof(p));
		p[0] = 1;
		for(i = 0;i < m;i++)
			scanf("%d%d%d",&data[i].t,&data[i].s,&data[i].d);
		qsort(data,m,sizeof(data),cmp);
		for(i = 0;i < m;i++){
			if(p[data[i].s - 1])
				p[data[i].d - 1] = 1;
		}
		count = 0;
		for(i = 0;i < n;i++)
			if(p[i]) count++;
		printf("%d\n",count);
	}
	return 0;
}

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

const int MAX_N = 200000;
typedef pair<int, pair<int, int > > P;

vector<P> v;
bool vis[MAX_N];

int main() {
  int N, M;
  while(cin >> N >> M && (N || M)) {
    P p;
    v.clear();    
    for(int i = 0; i < M; ++i) {
      cin >> p.first >> p.second.first >> p.second.second;
      --p.second.first; --p.second.second;
      v.push_back(p);
    }
    sort(v.begin(), v.end());
    fill(vis, vis+N, false);
    vis[0] = true;
    int ans = 1;
    for(int i = 0; i < v.size(); ++i) {
      if(vis[v[i].second.first]) {
	vis[v[i].second.second] = true;
	++ans;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#define REP(i,n) for (int i=0;i<(n);i++)

using namespace std;
struct com{
	int t,s,d;
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int n,m;
	while(cin>>n>>m,n){
		vector<com> computer(m);
		vector<char> infected(n,0);
		infected[0] = 1;
		REP(i,m){
			int t,s,d;
			cin >> t >> s >> d;
			computer[i] = {--t,--s,--d};
		}
		sort(computer.begin(),computer.end(),[](com a,com b){
				return a.t < b.t;
			});
		REP(i,m){
			infected[computer[i].d] |= infected[computer[i].s];
		}
		cout << accumulate(infected.begin(),infected.end(),0) << 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[n+1]={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;
	}
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

class UFT {
private:
  vi data, rnk;

public:
  UFT(const int &size)
    : data(size), rnk(size) {
    iota(all(data), 0);
  }

  int root(const int &x) {
    return data[x] == x ? x : data[x] = root(data[x]);
  }

  bool same(const int &a, const int &b) {
    return root(a) == root(b);
  }

  void unite(int a, int b) {
    a = root(a), b = root(b);
    if (a == b) return;
    if (rnk[a] < rnk[b]) swap(a, b);
    data[b] = a;
    if (rnk[a] == rnk[b]) rnk[a]++;
  }
};

void solve() {
  int n, m;
  while (cin >> n >> m, n) {
    vector<tuple<int, int, int>> v;
    while (m--) {
      int t, s, d;
      cin >> t >> s >> d;
      v.emplace_back(t, --s, --d);
    }
    sort(all(v));
    UFT uf(n);
    rep(i, v.size()) {
      int s, d;
      tie(ignore, s, d) = v[i];
      if (uf.same(0, s)) uf.unite(0, d);
    }
    int c = 0;
    rep(i, n) c += uf.same(0, i);
    cout << c << endl;
  }
}

C++: #include<bits/stdc++.h>
#define N 20001
using namespace std;

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

int main(){
  while(1){
  int n,m,f[N]={},cnt=1;
  data da[N];
  cin>>n>>m;
  if(n+m==0) break;
  f[1]=1;
  for(int i=0;i<m;i++)cin>>da[i].t>>da[i].s>>da[i].d;
  
    for(int i=0;i<m-1;i++)
    for(int j=m-1;j>=0;j--)
    if(da[j].t<da[j-1].t)swap(da[i],da[j]);
        
    for(int i=0;i<m;i++){
      if(f[da[i].s]==1)f[da[i].d]=1;
      if(da[i].s==1)f[da[i].d]=1;
    }
    for(int i=2;i<=n;i++) if(f[i]==1)cnt++;
    cout<<cnt<<endl;
  }
 
  
  return 0;
}