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++: #pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using ull=unsigned long long int;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
 while(1){
   ll n,m;
   cin>>n>>m;
   if(n==0)return 0;
   V<bool> infect(n,false);
   infect[0]=true;
   V<pair<int,P>> dat(m);
   for(int i=0;i<m;i++){
     ll t,s,d;
     cin>>t>>s>>d;
     s--;d--;
     dat[i]={t,P(s,d)};
   }
   sort(all(dat));
   for(int i=0;i<m;i++){
     infect[dat[i].se.se]=infect[dat[i].se.fi]|infect[dat[i].se.se];
   }
   int ans=0;
   for(int i=0;i<n;i++)if(infect[i])ans++;
   cout<<ans<<"\n";
 }
}

C++: #include<bits/stdc++.h>
#define N 20001
using namespace std;
 
struct data{
  long long t;
  int s,d;
};
 
int main(){
  while(1){
  int n,m,f[N]={},cnt=1;
  data da[N];
  cin>>n>>m;
  if(n+m==0) break;
  f[1]=1;
  for(int i=0;i<m;i++)cin>>da[i].t>>da[i].s>>da[i].d;
   
    for(int i=0;i<m-1;i++)
    for(int j=m-1;j>i;j--)
    if(da[j].t<da[j-1].t)swap(da[j],da[j-1]);
         
    for(int i=0;i<m;i++){
      if(f[da[i].s]==1)f[da[i].d]=1;
      if(da[i].s==1)f[da[i].d]=1;
    }
    for(int i=2;i<=n;i++) if(f[i]==1)cnt++;
    cout<<cnt<<endl;
  }
  
   
  return 0;
}

C++: #include<iostream>
#include<algorithm>
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){
    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)){
	ans++;
	if(!same(1,l[i].d))unite(1,l[i].d);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
#define p pair<int,int>
#define P pair<int,p>
using namespace std;

bool c[20000];
int main() {
	int a, b;
	while (cin >> a >> b, a | b) {
		memset(c, false, sizeof(c));
		c[0] = true;
		P d[20000];
		for (int e = 0; e < b; e++) {
			int f, g, h; scanf("%d%d%d", &f, &g, &h); g--; h--;
			d[e] = P(f, p(g, h));
		}
		sort(d, d + b);
		for (int e = 0; e < b; e++) {
			if (c[d[e].second.first]) {
				c[d[e].second.second] = true;
			}
		}
		int e = 0;
		for (bool f : c) {
			if (f)e++;
		}
		cout << e << endl;
	}
}

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long

struct edge{ int from, to, cost; };


int n, m;
bool used[20005];

bool comp(const edge& e1, const edge& e2)
{
	return e1.cost < e2.cost;
}

int main()
{
	while (cin >> n >> m, n)
	{
		edge es[20005];
		REP(i, m)
		{
			int a, b, c;
			cin >> a >> b >> c;
			c--; b--;
			es[i] = edge{ b, c, a };
		}
		sort(es, es + m, comp);
		memset(used, false, sizeof(used));
		used[0] = true;
		REP(i, m)
		{
			if (used[es[i].from]) used[es[i].to] = true;
		}
		int cnt = 0;
		REP(i, n)
		{
			if (used[i]) cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}

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 <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#define llint long long

using namespace std;
typedef pair<llint, llint> P;
typedef pair<llint, P> E;

llint n, m;
vector<E> vec;
bool used[20005];

int main(void)
{
	while(1){
		cin >> n >> m;
		if(n == 0) break;
		
		vec.clear();
		llint t, s, d;
		for(int i = 1; i <= m; i++){
			cin >> t >> s >> d;
			vec.push_back(E(t, P(s, d)));
		}
		sort(vec.begin(), vec.end());
		
		for(int i = 1; i <= n; i++) used[i] = false;
		used[1] = true;
		
		for(int i = 0; i < vec.size(); i++){
			llint s = vec[i].second.first, t = vec[i].second.second;
			used[t] |= used[s];
		}
		
		llint ans = 0;
		for(int i = 1; i <= n; i++){
			if(used[i]) ans++;
		}
		cout << ans << endl;
	}
	return 0;
}