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>
#define N 20001
using namespace std;
struct set{
  int t;
  int s;
  int d;
};
int main(){
  int n,m,i,j,cnt,source,destination,start,end[N],flag;
  struct set data[N];
  while(1){
    for(i=1;i<N;i++) end[i]=0;
    end[1]=1;
    cin >> n >> m;
    if(n==0&&m==0) break;
    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[j].t<data[j-1].t) swap(data[j],data[j-1]);
      }
    }
    for(i=0;i<m;i++){
      if(end[data[i].s]==1) end[data[i].d]=1;
    }
    cnt=0;
    for(i=1;i<=n;i++) if(end[i]==1) cnt++;
    cout << cnt << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<algorithm>
#include<complex>
#include<cstdlib>
#include<cctype>

#define DBG cout << '!' << endl;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cout << v[i] << ' ';cout << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cout << v[a][b] << ' ';cout << endl;}cout << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	int n,m;
	
	while(cin>>n>>m,n|m)
	{
		vector<pair<int,pair<int,int> > > v;
		int infected[n+1] = {};
		infected[1] = 1;
		
		
		REP(i,m)
		{
			int t,s,d;
			
			cin >> t >> s >> d;
			
			v.PB(MP(t,MP(s,d)));
		}
		
		sort(ALL(v));
		
		REP(i,m)
		{
			if(infected[v[i].SE.FI])
				infected[v[i].SE.SE] = 1;
		}
		
		int ans = 0;

		REP(i,n+1)
		{
			ans += infected[i];
		}
		
		cout << ans << endl;
	}
	return 0;
}

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

bool func(const pair< int, pair<int,int> > a, const pair< int, pair<int, int> > b){
    return a.first < b.first;
}

int main(void){
    int N, M;
    while(cin >> N >> M, N | M){
        vector<bool> v(N, false);
        v[0] = true;
        vector< pair< int, pair<int, int> > > p(M);
        for(int i = 0; i < M; i++){
            int a, b, c; cin >> a >> b >> c;
            b--; c--;
            p[i].first = a;
            p[i].second.first = b;
            p[i].second.second = c;
        }
        sort(p.begin(), p.end(), func);
        for(int i = 0; i < M; i++) v[ p[i].second.second ] = v[ p[i].second.second ] || v[ p[i].second.first ];
        int ans = 0;
        for(int i = 0; i < N; i++){
            if(v[i] == true) ans++;
        }
        cout << ans << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstring>
#include <string>
#include <sstream>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define SORT(x) sort((x).begin(), (x).end())
#define clr(a,b) memset((a),(b),sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<PP> Vpp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

bool cp[20001];

int main(){
	int n,m;
	while(scanf("%d%d", &n, &m), n||m){
		rep(i,20001) cp[i] = false;
		cp[1] = true;
		Vpp vec;
		rep(i,m){
			int a,b,c;
			scanf("%d%d%d", &a, &b, &c);
			vec.pb(PP(a,P(b,c)));
		}
		SORT(vec);
		rep(i,m){
			if(!cp[vec[i].sec.fi]) continue;
			cp[vec[i].sec.sec] = true;
		}
		int ans = 0;
		rep(i,20001) if(cp[i]) ans++;
		printf("%d\n", ans);
	}
}

C++: #include<map>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int n,m;
  while(cin>>n>>m&&(n||m)){
    map<int,pair<int,int> > a;
    for(i=0;i<m;i++){
      int p,q,r;
      cin>>p>>q>>r;
      q--;
      r--;
      a[p]=make_pair(q,r);
    }
    bool b[20000];
    memset(b,0,20000);
    b[0]=1;
    map<int,pair<int,int> >::iterator it;
    for(it=a.begin();it!=a.end();it++){
      if(b[(*it).second.first])
	b[(*it).second.second]=1;
    }
    int ct=0;
    for(i=0;i<n;i++)
      ct+=b[i];
    cout<<ct<<endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
struct dts{
    int t;
    int s;
    int d;
};

int main(void){
    int N,M,i,cnt;
    while(1){
        scanf("%d",&N);
        scanf("%d",&M);
        if(!N && !M){break;}
        int pcs[N];
        vector<dts> datas;
        for(i=0;i<N;i++){pcs[i]=0;}
        pcs[0]=1;
        cnt=0;
        for(i=0;i<M;i++){
            struct dts buf;
            scanf("%d",&buf.t);
            scanf("%d",&buf.s);
            scanf("%d",&buf.d);
            datas.push_back(buf);
        }
        sort(datas.begin(),datas.end(),[](const dts& x,const dts& y){return x.t < y.t;});
        for(i=0;i<M;i++){
            if(pcs[datas[i].s-1]){pcs[datas[i].d-1]=1;}
        }
        for(i=0;i<N;i++){if(pcs[i]){cnt++;}}
        printf("%d\n",cnt);
    }
    return 0;
}