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>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

#define N 20005

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

void bubbleSort(struct q q[N], int n){
    rep(i,n){
        rep(j,n - 1){
            if(q[j].t > q[j + 1].t){
                struct q temp = q[j];
                q[j] = q[j + 1];
                q[j + 1] = temp;
            }
        }
    }
}


int main(){
    int n, m;
    while(cin >> n >> m,n||m){
        bool com[N] = {0};
        com[1] = true;
        q q[N];
        rep(i,m){
            cin >> q[i].t >> q[i].s >> q[i].d;
        }
        bubbleSort(q, m);
        rep(i,m){
            if(com[q[i].d] != 1) com[q[i].d] = com[q[i].s];
        }
        int sum = 0;
        rep(i,n + 1) sum+=static_cast<int>(com[i]);
        cout << sum << endl;
    }
}

C++: #include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
typedef pair<int, pair<int,int> > data;
int main(){
  int n,m;
  cin >> n >> m ;
  int i,j,k;
  while((n+m)!=0){
    int ns[20010]={};
    vector <data> ds;
    data d;
    for(i=0;i<m;i++){
      cin >> d.first >> d.second.first >> d.second.second;
      ds.push_back(d);
    }
    sort(ds.begin(),ds.end());
    int o=1;
    ns[1]=1;
    for(i=0;i<m;i++){
      if(ns[ds[i].second.first]==1&&ns[ds[i].second.second]==0) {
	ns[ds[i].second.second]=1;
	o++;
      }
    }
    cout << o << endl;
    cin >> n >> m ;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
struct log{
  int T,s,d;
  bool operator<(const log &a)const{
    return T<a.T;
  }
};
const int MAX_N=30000;
int parent[MAX_N];
int depth[MAX_N];

void init(int n){
  for(int i=0;i<n;i++){
    parent[i]=i;
    depth[i]=0;
  }
}

int find(int x){
  if(parent[x]==x){
    return x;
  }else{
    return parent[x]=find(parent[x]);
  }
}

void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y)return;
  if(depth[x]<depth[y]){
    parent[x]=y;
  }else{
    parent[y]=x;
    if(depth[x]==depth[y])depth[x]++;
  }
}

bool same(int x,int y){
  return find(x)==find(y);
}

log l[30000];
int main(){
  int n,m;
  while(cin>>n>>m,n){
    memset(l,0,sizeof(l));
    init(n+1);
    for(int i=0;i<m;i++)
      cin>>l[i].T>>l[i].s>>l[i].d;
    sort(l,l+m);
    int ans=1;
    for(int i=0;i<m;i++){
      if(same(1,l[i].s)){
	ans++;
	if(!same(1,l[i].d))unite(1,l[i].d);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <utility>
#include <typeinfo>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main() 
{
	int n,m;
	while(cin>>n>>m&&!(n==0&&m==0))
	{
		pair<int,int> a[20000],b[20000];
		REP(i,m)
		{
			int x,y,z;
			cin>>x>>y>>z;
			y-=1;z-=1;
			a[i] = make_pair(x,y);
			b[i] = make_pair(x,z);
		}
		sort(a,a+m);
		sort(b,b+m);
		
		bool inf[20000]={};
		inf[0]=true;
		
		int ans(1);
		REP(i,m){if(inf[a[i].second]&&!inf[b[i].second]){inf[b[i].second]=true;ans++;}}

		cout<<ans<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
long long a[200001];
long long inf = 9000000000;
struct P{
	long long time, pos;
};
bool operator<(P a, P b) { return a.time < b.time; }
bool operator>(P a, P b) { return a.time > b.time; }
struct B {
	long long time, to;
};
vector<B>e [200001];
int main() {
	long long n,m;
	while (cin >> n>>m&&(n != 0&&m!=0)) {
		for (int i = 0; i <= n; i++) {
			a[i] = inf;
			e[i].clear();
		}
		for (int i = 0; i < m; i++) {
			int a, b, c;
			cin >> a >> b >> c;
			e[b].push_back(B{ a,c });
		}
		a[1] = 0;
		priority_queue<P, vector<P>, greater<P>>p;
		p.push(P{ 0,1 });
		while (!p.empty()) {
			P t = p.top(); p.pop();
			if (a[t.pos] != inf) {
				for (int i = 0; i < (int)e[t.pos].size(); i++) {
					if (a[e[t.pos][i].to] > a[t.pos] + e[t.pos][i].time) {
						a[e[t.pos][i].to] = a[t.pos] + e[t.pos][i].time;
						p.push(P{ a[e[t.pos][i].to],e[t.pos][i].to });
					}
				}
			}
		}
		long long sum = 0;
		for (int  i = 1; i <= n; i++) {
			if (a[i] != inf) sum++;
		}
		cout << sum << endl;
	}
}

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

using namespace std;

struct packet_t {
  uint32_t t;
  uint32_t s;
  uint32_t d;

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

int32_t main() {
  while (true) {
    uint32_t N, M;
    cin >> N >> M;
    if (N == 0) break;

    vector<packet_t> packets;
    for (uint32_t i = 0; i < M; i++) {
      uint32_t t, s, d;
      cin >> t >> s >> d;
      packet_t p({t, s, d});
      packets.push_back(p);
    }

    sort(packets.begin(), packets.end());
    vector<bool> infected(N + 1);
    infected[1] = true;
    for (uint32_t i = 0; i < packets.size(); i++) {
      if (infected[packets[i].s]) {
        infected[packets[i].d] = true;
      }
    }

    uint32_t count = 0;
    for (uint32_t i = 1; i <= N; i++) {
      if (infected[i]) {
        count++;
      }
    }
    cout << count << endl;
  }

  return 0;
}