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>
#include<algorithm>
using namespace std;
typedef pair<long long, pair<int, int>> p;
int main() {
    int n, m;
    while (cin >> n >> m, n, m) {
        bool b[20010] = {};
        b[1] = true;
        p a[20010];
        for (int i = 0; i < m; i++)cin >> a[i].first >> a[i].second.first >> a[i].second.second;
        sort(a, a + m);
        for (int i = 0; i < m; i++) 
            if (b[a[i].second.first])b[a[i].second.second] = true;
        int ans = 0;
        for (int i = 1; i <= n; i++)if (b[i])ans++;
        cout << ans << endl;
    }
}

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

struct Computer{
  int time,saki,source;
};

int main(){
  Computer computer[20001];
  int data[20001];
 

  while(1){
    int n,m; cin >> n >> m;
    if( n == 0 && m == 0 ) break;
    
    for( int i = 0; i < 20001; i++ ) data[i] = 0;
    data[1] = 1;
    
    for( int i = 1; i <= m; i++ )
      cin >> computer[i].time >> computer[i].source >> computer[i].saki;

    for( int i = 1; i <= m; i++ ){
      for( int j = 1; j < m; j++ ){
	if( computer[j].time > computer[j+1].time ) swap(computer[j],computer[j+1]);
      }
    }
    
    // for( int i = 1; i <= m; i++ ) cout << "i " << i  << " "  << computer[i].time << " " << endl;
    
    for( int i = 1; i <= m; i++ ){
      if( data[ computer[i].source ] == 0 && data[ computer[i].saki ] == 1 ) continue;
      data[ computer[i].saki ] = data[ computer[i].source ];
    }

    int cnt = 0;

    //  for( int i = 1; i <= n; i++ ) cout << data[i] << " ";
    //cout << endl;
    
    for( int i = 1; i <= n; i++ ){
      if( data[i] == 1 ) cnt++;
    }

     cout << cnt << endl;

  }
  return 0;
}

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

struct data{int t,s,d;};
bool compare(const data& a, const data& b){return a.t < b.t;}

int main(){

  for(int n,m;cin>>n>>m,n;){
    vector<int> flags(n,0);flags[0]=1;
    vector<data> logs(m);

    for(int i=0;i<m;++i)
      cin >> logs[i].t >> logs[i].s >> logs[i].d;

    sort(logs.begin(), logs.end(), compare);

    for(int i=0;i<m;++i)
      flags[logs[i].d-1] |= flags[logs[i].s-1];

    int ans=0;
    for(int i=0;i<n;++i)
      ans += flags[i];

    cout << ans << endl;
  }

  return EXIT_SUCCESS;
}

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 <queue>
#include <algorithm>
#include <tuple>
using namespace std;
using T = tuple<int,int,int>;
bool isInfected[20000];
vector<T> V;

int main(){
    int N,M;
    while(cin>>N>>M,N){
        V.clear();
        for(int i=0;i<M;i++){
            int t,s,d;
            cin>>t>>s>>d;
            V.emplace_back(t,s-1,d-1);
        }
        sort(V.begin(), V.end());
        fill(isInfected,isInfected+20000,false);
        isInfected[0]=true;
        for(auto v:V){
            int t,s,d;
            tie(t,s,d)=v;
            if(isInfected[s])isInfected[d]=true;
        }

        int ans=0;
        for(int i=0;i<N;i++) ans+=isInfected[i];
        cout<<ans<<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;
  }
};

array<logs, 20000> data;

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(ALL(data));
    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;
  }
}