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>
using namespace std;
typedef long long ll;
#define f(i,x,n) for(int i=x;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;
int dp[13][203];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N,M;cin>>N>>M;
        if(N+M==0) break;
        
        vector<int> T(M),A(M),B(M),id(M),state(N+1);
        state[1]=1;
        for(int i=0;i<M;i++){
            cin>>T[i]>>A[i]>>B[i];
        }
        iota(all(id),0);
        
        sort(all(id),[&](int a,int b){
            return T[a]<T[b];
        });
        
        for(int i=0;i<M;i++){
            if(state[A[id[i]]]){
                state[B[id[i]]]=1;
            }
        }
        
        int ans=0;
        
        for(int i=1;i<=N;i++) ans+=state[i];
        
        cout<<ans<<endl;
        
    }
}

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

class Flow{
public:
    int t,s,d;
    bool operator<(const Flow &f)const{
        return f.t>this->t;
    }
};

int main(){
    int n,m;
    while(cin>>n>>m&&!(n==0&&m==0)){
        vector<Flow> v;
        for(int i = 0; i < m; i++){
            Flow f;
            cin>>f.t>>f.s>>f.d;
            v.push_back(f);
        }
        sort(v.begin(),v.end());
        bool isInfected[20001];
        fill(isInfected,isInfected+20001,false);
        isInfected[1]=true;
        int cnt=1;
        for(int i = 0; i < v.size(); i++){
            if(isInfected[v[i].s]&&!isInfected[v[i].d]){
                isInfected[v[i].d]=true;
                cnt++;
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main() {
  while(1){
    int n,m;
    cin>>n>>m;
    if(!n)break;
    vector<bool> inf(n,false);
    inf[0] = true;
    vector<tuple<int,int,int>> pkt;
    REP(i,m){
      int t,s,d;
      cin>>t>>s>>d;
      --s;--d;
      pkt.emplace_back(t,s,d);
    }
    sort(begin(pkt),end(pkt));
    for (auto p:pkt){
      int t,s,d;
      tie(t,s,d) = p;
      if (inf[s])
        inf[d] = true;
    }
    cout<<count(begin(inf),end(inf),true)<<endl;
  }
  return 0;
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

int main() {

  for (int n, m; cin >> n >> m, n || m;) {
    vector<pair<int, pair<int, int>>> ps;
    rep (i, m) {
      int t, s, d; cin >> t >> s >> d;
      --s; --d;
      ps.push_back(cons( t, cons(s, d)));
    }
    sort(all(ps));

    vector<bool> is(n, false);
    is[0] = true;
    for (auto&p : ps) {
      if (is[cadr(p)]) is[cddr(p)] = true;
    }
    int cx = 0;
    rep (i, n) { if (is[i]) ++cx; }
    cout << cx << endl;
  }

  return 0;
}

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

using namespace std;

#define MAX 20000

struct edge{
  int from, to, cost;

  edge(int from = -1, int to = -1, int cost = -1) 
    : from(from), to(to), cost(cost) {}

  bool operator < (const edge &e)const{
    return cost < e.cost;
  }
};

int main(){
  int N, M, t, s, d;

  while(cin >> N >> M , N){
    edge e[MAX];

    for(int i = 0 ; i < M ; i++){
      cin >> t >> s >> d;
      e[i] = edge(s-1, d-1, t);
    }
    
    sort(e, e+M);
    bool check[MAX] = {false};
    check[0] = true;

    for(int i = 0 ; i < M ; i++){
      if(check[e[i].from]){
	check[e[i].to] = true;
      }
    }
    
    int ans = 0;
    for(int i = 0 ; i < N ; i++){
      if(check[i]) ans++;
    }
    cout << ans << endl;
  }

  return 0;
}

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,n);
    b[0]=1;
    map<int,pair<int,int> >::iterator it;
    for(it=a.begin();it!=a.end();it++)
      b[(*it).second.second]|=b[(*it).second.first];
    int ct=0;
    for(i=0;i<n;i++)
      ct+=b[i];
    cout<<ct<<endl;
  }
  return 0;
}