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

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

#define REP(i, n) for(int i = 0; i < (int) (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9+7

using namespace std;
bool infected[20000];

struct logs{
  int t, f, d;
  logs(int t, int f, int d) : t(t), f(f), d(d) {}
  logs() : t(INF), f(0), d(0) {}
  bool operator<(logs &x)const{
    if(t < x.t) return true;
    return false;
  }
};

logs data[20000];

int main(){
  int n, m;
  while(cin >> n >> m and n + m){
    memset(infected, 0, sizeof(infected));
    REP(i, 20000){
      data[i] = logs();
    }
    REP(i, m){
      int t, s, d;
      cin >> t >> s >> d; s--; d--;
      data[i] = logs(t, s, d);
    }
    sort(data, data+m);
    infected[0] = true;
    REP(i, m){
      if(infected[data[i].f]) infected[data[i].t] = true;
      else infected[data[i].t] = false;
    }
    int res = 0;
    REP(i, n) if(infected[i]) res++;
    cout << res << endl;
  }
}

C++: #include<iostream>
#include<vector>
using namespace std;main(){for(int N,M,i;cin>>N>>M,N;cout<<N<<endl){vector<int>v(N+1),s(M+1),d(M+1);for(i=0;i++<M;cin>>s[N]>>d[N])cin>>N;v[1]=N=1;for(i=0;i++<M;)if(v[s[i]]){v[d[i]]=1;v[d[i]]||N++;}

C++: #include<stdio.h>
#include<algorithm>
#include<bitset>
const int N=20001;
struct S{int t,s,d;}a[N];
int C(S l,S r){return l.t<r.t;}
int main()
{
	int n,m,i;
	std::bitset<N>b;
	while(scanf("%d%d",&n,&m),n)
	{
		for(i=1;i<=m;++i)scanf("%d%d%d",&a[i].t,&a[i].s,&a[i].d);
		std::sort(a+1,a+1+m,C);
		b.reset();
		n=b[1]=1;
		for(i=1;i<=m;++i)if(b[a[i].s]&&!b[a[i].d])b[a[i].d]=1,++n;
		printf("%d\n",n);
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 20005;
bool com[MAX_N];
struct DATA{
	int t, s, d;

	bool operator<( const DATA & right ) const {
		return (t < right.t );
	}
};
	
int main()
{
	ios_base::sync_with_stdio(0);
	int N, M;
	while (cin >> N >> M, N ){
		memset (com, false, sizeof (com ) );
		DATA data[M];
		rep (i, M ){
			cin >> data[i].t >> data[i].s >> data[i].d;
		} // end rep
		sort (data, data + M );
		com[1] = true;
		rep (i, M ){
			com[data[i].d] |= com[data[i].s];
		} // end rep
		int res = (int)count (com, com + N + 1, true );
		cout << res << endl;
	} // end while
	
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n,m,t,s,d;
	while(cin>>n>>m,n){
		vector<pair<int,pair<int,int> > >p(m);
		rep(i,m)cin>>t>>s>>d,p[i]=make_pair(t,make_pair(s-1,d-1));
		sort(p.begin(),p.end());
		bool f[n]; rep(i,n)f[i]=i==0;
		int ans=1;
		rep(i,m)if(f[p[i].second.first])ans++,f[p[i].second.second]=1;
		cout<<ans<<endl;
	}
	return 0;
}