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 <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii>  ppii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n,m;
    while(cin>>n>>m,n+m){
        map<int,int>mp;
        vector<ppii>v;
        rep(i,m){
            int t,s,d; cin>>t>>s>>d;
            v.push_back(ppii(t,pii(s,d)));
        }
        mp[1]=1;
        sort(all(v));
        rep(i,v.size()){
            if(mp[v[i].second.first])mp[v[i].second.second]=1;
        }
        int ans=0;
        for(int i=0; i<=n;i++)
            if(mp[i])ans++;
        cout<<ans<<endl;
    }
}

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

struct Data{
  
  int t,s,d;

  bool operator<(const Data& data)const{
    if(data.t != t)return t < data.t;  
    if(data.s != s)return s < data.s;
    return d < data.d;
  }
  
};
int main(){

  int N,M;
  
  while(1){

    cin >>N>>M;
    if(N==0 && M==0)break;
    
    Data data[M];
    for(int i=0 ; i < M ; i++){
      cin >>data[i].t>>data[i].s>>data[i].d;
    }
    
    sort(data,data+M);
    
    bool isinfected[N+1];
    for(int i=1 ; i <= N ; i++)isinfected[i]=false;
    isinfected[1]=true;
    
    int cnt=1;
    for(int i=0 ; i < M ; i++){
      if(isinfected[data[i].s] && !isinfected[data[i].d]){
	isinfected[data[i].d]=true;
	cnt++;
      }
    }
    
    cout <<cnt<<endl;
    
  }
  
  return 0;
}

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

using namespace std;

struct tsd {
	int t, s, d;
	bool operator<(const tsd& a) const { return t < a.t; }
};

int main() {
	int n, m; 
	while(cin >> n >> m, n) {
		vector<bool> isinfect(n + 1);
		isinfect[1] = true;
		vector<tsd> data(m);
		for (int i = 0; i < m; ++i) cin >> data[i].t >> data[i].s >> data[i].d;
		sort(data.begin(), data.end());
		for (auto a:data)
			if (isinfect[a.s]) isinfect[a.d] = true;
		int ans = 0;
		for (int i = 1; i <= n; ++i) if (isinfect[i]) ans++;
		cout << ans << endl;
	}

	return 0;
}

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

#define MAX_N 100000

tuple<int, int, int>X[MAX_N];
int n, m, a, b, c;
int V[MAX_N];

int main() {
	while (true) {
		for (int i = 0; i < MAX_N; i++) {
			X[i] = make_tuple(0, 0, 0);
			V[i] = 0;
		}
		V[1] = 1;
		cin >> n >> m;
		if (n == 0 && m == 0) {
			break;
		}
		for (int i = 0; i < m; i++) {
			cin >> a >> b >> c;
			X[i] = make_tuple(a, b, c);
		}
		sort(X, X + n);
		for (int i = 0; i < m; i++) {
			int a1 = get<0>(X[i]);
			int a2 = get<1>(X[i]);
			int a3 = get<2>(X[i]);
			if (V[a2] == 1) {
				V[a3] = 1;
			}
		}
		int sum = 0;
		for (int i = 0; i < MAX_N; i++) {
			sum += V[i];
		}
		cout << sum << endl;
	}
}

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);
    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) && !same(1,l[i].d)){
	ans++;
	unite(1,l[i].d);
      }
    }
    cout << ans << endl;
  }
  return 0;
}