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;

int main(){
        int n,w;
        while(cin>>n>>w,n){
                vector<int> v(n);
                for(int i=0;i<n;i++) cin>>v[i];

                double res=0.01;
                vector<int> height(11,0);
                for(int i=0;i<n;i++){
                        int h=0;
                        int val=v[i];
                        for(;w<=val;h++) val-=w;
                        height[h]++;
                }
                int rigmost=0;
                for(int i=0;i<11;i++) rigmost=max(rigmost,i*(height[i]!=0));
                int highest=*max_element(height.begin(),height.end());

                for(int i=0;i<=rigmost;i++){
                        res+=double(height[i])/highest*double(rigmost-i)/(rigmost);
                }
                cout<<fixed<<setprecision(10);
                cout<<res<<endl;
        }

}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-9;
const double PI  = acos(-1.0);

int main(){
	int n,m;
	while(cin>>n>>m,n|m){
		vector<pair<int,pii> > tsd(m);
		REP(i,m){
			cin>>tsd[i].first>>tsd[i].second.first>>tsd[i].second.second;
		}
		sort(ALL(tsd));
		vi inf(n+1);
		inf[1]=1;
		REP(i,m){
			if(inf[tsd[i].second.first]){
				inf[tsd[i].second.second]=1;
			}
		}
		cout<<count(inf.begin()+1,inf.end(),1)<<endl;
	}
}

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

int main()
{
  vector<pair<int,pair<int,int> > > PC;
  int N,M,t,s,d,c,p[20001],start;

  while(1){
    cin>>N>>M;
    if(N==0&&M==0)break;
    PC.clear();
    start=1000000002;
    for(int i=0;i<20002;i++)p[i+1]=0;
    for(int i=0;i<M;i++){
      cin>>t>>s>>d;
      PC.push_back(make_pair(t,make_pair(s,d)));
      if(s==1){
	start=t;
	p[1]=1;
      }
    }
    c=1;

    sort(PC.begin(),PC.end());

    for(int i=0;i<M;i++){
      if(start<=PC[i].first){
	if(p[PC[i].second.first]==1)p[PC[i].second.second]=1;
      }
    }
    for(int i=1;i<20002;i++){
      if(p[i+1]==1)c++;
    }
    cout<<c<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
 
int main(){
  int n,m,i,t,s,d;
  for(;cin>>n>>m,n;){
    vector<pair<int,pair<int,int> > >V;
    set<int> S;
    S.insert(1);
    for(i=0;i<m;i++){
      cin>>t>>s>>d;
      V.push_back(make_pair(t,make_pair(s,d)));
    }
     for(i=0;i<m;i++)
      if(S.find(V[i].second.first)!=S.end())
        S.insert(V[i].second.second);
    cout<<S.size()<<endl;
  }
}

C++: #include <cstdio>
#include <cstdlib>
#include <utility>
#include <typeinfo>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main() 
{
	int n,m;
	while(cin>>n>>m&&!(n==0&&m==0))
	{
		pair<int,int> a[20000],b[20000];
		REP(i,m)
		{
			int x,y,z;
			scanf("%d%d%d",&x,&y,&z);
			y-=1;z-=1;
			a[i] = make_pair(x,y);
			b[i] = make_pair(x,z);
		}
		sort(a,a+m);
		sort(b,b+m);
		
		bool inf[20000]={};
		inf[0]=true;
		
		int ans(1);
		REP(i,m){if(inf[a[i].second]&&!inf[b[i].second]){inf[b[i].second]=true;++ans;}}

		printf("%d\n",ans);
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <utility>
#include <typeinfo>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main() 
{
	int n,m;
	while(cin>>n>>m&&!(n==0&&m==0))
	{
		pair<int,int> a[20000],b[20000];
		REP(i,m)
		{
			int x,y,z;
			cin>>x>>y>>z;
			y-=1;z-=1;
			a[i] = make_pair(x,y);
			b[i] = make_pair(x,z);
		}
		sort(a,a+m);
		sort(b,b+m);
		
		bool inf[20000]={};
		inf[0]=true;
		//REP(i,n)cout<<inf[i];cout<<endl;
		REP(i,m){if(inf[a[i].second]){inf[b[i].second]=true;}}
		//REP(i,n)cout<<inf[i];cout<<endl;
		int ans(0);
		REP(i,n)ans+=inf[i];
		
		cout<<ans<<endl;
	}
	return 0;
}