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 <cstdio>
#include <vector>
using namespace std;
struct dts{
    int t;
    int s;
    int d;
};

int main(void){
    int N,M,i,cnt;
    while(1){
        scanf("%d",&N);
        scanf("%d",&M);
        if(!N && !M){break;}
        int pcs[N];
        vector<dts> datas;
        for(i=0;i<N;i++){pcs[i]=0;}
        pcs[0]=1;
        cnt=0;
        for(i=0;i<M;i++){
            struct dts buf;
            scanf("%d",&buf.t);
            scanf("%d",&buf.s);
            scanf("%d",&buf.d);
            datas.push_back(buf);
        }
        sort(datas.begin(),datas.end(),[](const dts& x,const dts& y){return x.t < y.t;});
        for(i=0;i<M;i++){
            if(pcs[datas[i].s-1]){pcs[datas[i].d-1]=1;}
        }
        for(i=0;i<N;i++){if(pcs[i]){cnt++;}}
        printf("%d\n",cnt);
    }
    return 0;
}

C++: #include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n,m;
	while(cin>>n>>m,n||m){
		bool infect[n+1];
		rep(i,n+1)infect[i]=false;
		infect[1]=true;
		long long ans=1;
		long long t[m];
		int s[m],d[m];
		rep(i,m)cin>>t[i]>>s[i]>>d[i];
		for(int i=m;i>=0;i--){
			for(int j=0;j<i-1;j++){
				if(t[j]>t[j+1]){
					long long alt=t[j];
					t[j]=t[j+1];
					t[j+1]=alt;
					alt=s[j];
					s[j]=s[j+1];
					s[j+1]=alt;
					alt=d[j];
					d[j]=d[j+1];
					d[j+1]=alt;
				}
			}
		}
		rep(i,m){
			if(infect[s[i]]){
				if(!infect[d[i]])ans++;
				infect[d[i]]=true;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

struct data{
  int t,s,d,vi;
};

 data da[N];
int main(){
  while(1){
    int n,m,f[N]={},cnt=0,fl=0;
    memset(da+1,0,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;
    if(da[i].s==1)da[i].vi=1;
    else da[i].vi=0;
  }
   
  for(int i=0;i<m;i++){
    fl=0;
    if(da[i].vi==1){
      for(int j=0;j<m;j++){
	if(da[i].t < da[j].t && da[i].d==da[j].s)da[j].vi=1,fl=1;
	else if(da[i].d==da[j].s)fl=1;
      }
      if(fl==0)f[da[i].d]=1;
    }
  }
  
    for(int i=1;i<=n;i++) if(f[i]==1)cnt++;
    for(int i=0;i<=n;i++)if(da[i].vi==1 && da[i].s!=1)cnt++;
			  
    cout<<cnt<<endl;
  }
 
  
  return 0;
}

C++: //49
#include<iostream>
#include<algorithm>

using namespace std;

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

int main(){
  for(int n,m;cin>>n>>m,n|m;){
    E p[20000];
    for(int i=0;i<m;i++){
      int t,s,d;
      cin>>t>>s>>d;
      E c={t,s,d};
      p[i]=c;
    }
    sort(p,p+m);
    bool in[20001]={false,true};
    for(int i=0;i<m;i++){
      in[p[i].d]|=in[p[i].s];
    }
    cout<<count(in,in+n+1,true)<<endl;;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
#define X first
#define Y second
using namespace std;
bool f[20000];
int n,m;
pair<int,pair<int,int> >t[20000];
int main(){
	while(cin>>n>>m&&n+m){
	for(int i=1;i<n;i++)f[i]=0;
	f[0]=1;
	for(int i=0;i<m;i++){
		cin>>t[i].X>>t[i].Y.X>>t[i].Y.Y;
		t[i].Y.X--,t[i].Y.Y--;
	}
	sort(t,t+m);
	for(int i=0;i<m;i++){
		if(f[t[i].Y.X])f[t[i].Y.Y]=1;
	}
	int ans=0;
	for(int i=0;i<n;i++)ans+=f[i];
	cout<<ans<<endl;
	}
	getchar();
	getchar();
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m,n){
    long long a,b,c,k[20001]={};
    vector<pair<long long,pair<int,int> > > s;
    k[1]=1;
    for(int i=0;i<m;i++){
      cin>>a>>b>>c;
      s.push_back(make_pair(a,make_pair(b,c)));
    }

    for(int i=0;i<m;i++){
      if(k[s[i].second.first]==1)k[s[i].second.second]=1;
    }
    int ans=0;
    for(int i=1;i<=n;i++)ans+=k[i];
    cout<<ans<<endl;
  }
  return 0;
}

C++: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

class Packet{
public:
  int time,src,dst;
  Packet(int _t,int _s,int _d) : time(_t),src(_s),dst(_d){}
  bool operator<(const Packet& p) const{
    return time < p.time;
  }
  bool operator>(const Packet& p) const{
    return time > p.time;
  }
};

int main(){
  int computer_num,send_list_num;
  while(~scanf("%d %d",&computer_num,&send_list_num)){
    if(computer_num == 0 && send_list_num == 0) break;

    vector<Packet> packets;
    for(int i=0;i<send_list_num;i++){
      int time,src,dst;
      scanf("%d %d %d",&time,&src,&dst);
      packets.push_back(Packet(time,src,dst));
    }

    sort(packets.begin(),packets.end());
    
    bool infected[21];
    memset(infected,0,sizeof(infected));
    infected[1] = true;
    for(int i=0;i<packets.size();i++){
      if(infected[packets[i].src]){
	infected[packets[i].dst] = true;
      }
    }

    int res = 0;
    for(int i=1;i<=computer_num;i++){
      if(infected[i]) res++;
    }

    printf("%d\n",res);
  }
}