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 <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

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

int main() {
  int n,m;
  while(cin>>n>>m,n) {
    P p[m];
    REP(i,m) {
      int t,s,d;
      cin >> t>>s>>d;
      s--;d--;
      p[i] = (P){t,s,d};
    }
    sort(p,p+m);
    bool infected[n];
    memset(infected,0,sizeof(infected));
    infected[0] = 1;
    REP(i,m) {
      if (infected[p[i].s])
        infected[p[i].d] = 1;
    }
    int res = 0;
    REP(i,n) {
      if (infected[i]) res++;
    }
    cout << res << endl;
  }
}

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(end[data[i].s]==1&&end[data[i].d]==0){
	  cnt++;
	  end[data[i].d]=1;
	}
      }
      cout << cnt << endl;
    }
    else cout << 1 << endl;
  }
  
  return 0;
}

C++: #include <stdio.h>
#include <algorithm>
#include <tuple>
using namespace std;
int N, M; tuple<int, int, int> D[20000]; bool infected[20000];
int main() {
	while (true) {
		scanf("%d%d", &N, &M);
		if (N == 0 && M == 0) break;
		infected[0] = true;
		for (int i = 1; i < N; i++) infected[i] = false;
		for (int i = 0; i < M; i++) scanf("%d%d%d", &get<0>(D[i]), &get<1>(D[i]), &get<2>(D[i])), get<1>(D[i])--, get<2>(D[i])--;
		sort(D, D + M);
		int ret = 1;
		for (int i = 0; i < M; i++) {
			if (infected[get<1>(D[i])] && !infected[get<2>(D[i])]) {
				infected[get<2>(D[i])] = true; ret++;
			}
		}
		printf("%d\n", ret);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
typedef complex<double> P;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 29;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };


int main() {
	int n, m;
	while ( ~scanf( "%d %d", &n, &m ) && n && m ) {
		VI cpu( n, false );
		cpu[ 0 ] = true;
		vector<pair<int, PII> > d;
		for ( int i = 0; i < m; i++ ) {
			int time, from, to;
			scanf( "%d %d %d", &time, &from, &to );
			d.push_back( MP( time, MP( from - 1, to - 1 ) ) );
		}
		sort( d.begin(), d.end() );
		for ( int i = 0; i < m; i++ ) {
			if ( cpu[ d[ i ].second.first ] ) {
				cpu[ d[ i ].second.second ] = true;
			}
		}
		int ans = 0;
		for ( int i = 0; i < n; i++ ) {
			if ( cpu[ i ] ) {
				++ans;
			}
		}
		printf( "%d\n", ans );
	}
	return 0;
}