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 <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <fstream>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
typedef long long ll;

#define INF 1000000000

int main(){
    int n,m;
    while(cin>>n>>m, n|m){
        vector<bool> infected(n, false);
        vector<pair<int, pair<int, int> > > vec;

        rep(i,m){
            int t,s,d;
            scanf("%d %d %d", &t, &s, &d);
            s--; d--;
            vec.pb(mp(t, mp(s,d)));
        }

        sort(all(vec));

        infected[0]=true;
        int res=1;
        rep(i,m){
            if(infected[vec[i].second.first]){
                infected[vec[i].second.second] = true;
                res++;
            }
        }
        cout << res<< endl;
    }

    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))
	{
		pll a[10000],b[10000];
		REP(i,m)
		{
			ll 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[10000]={};
		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;
}

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

using namespace std;

int main(){
  int n,m,i;
  while(cin >> n >> m, n != 0 || m != 0) {
    int cnt = 1, data[20001][2] = {};
    int in[20001] = {};
    vector<int> v(0);
    in[1] = 1;
    for(i = 0; i < m; i++) {
      int t,s,g;
      cin >> t >> s >> g;
      data[t][0] = s;
      data[t][1] = g;
      v.push_back(t);
    }
    sort(v.begin(), v.end());
    for(i = 0; i < v.size(); i++) {
      if(in[data[v[i]][0]]){
	  if(in[data[v[i]][1]] == 0)
	    {
	      cnt++;
	      in[data[v[i]][1]] = 1;
	    }
	}
    }
      
    cout << cnt << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <set>
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;
        set<Flow> s;
        for(int i = 0; i < m; i++){
            Flow f;
            cin>>f.t>>f.s>>f.d;
            //v.push_back(f);
            s.insert(f);
        }
        //sort(v.begin(),v.end());
        bool isInfected[20001];
        fill(isInfected,isInfected+20001,false);
        isInfected[1]=true;
        int cnt=1;
        for(set<Flow>::iterator it = s.begin(); it != s.end(); it++){
            if(isInfected[it->s]&&!isInfected[it->d]){
                isInfected[it->d]=true;
                cnt++;
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
long long a[20001];
long long inf = 9000000000;
struct P{
	long long time, pos;
};
bool operator<(P a, P b) { return a.time < b.time; }
bool operator>(P a, P b) { return a.time > b.time; }
struct B {
	long long time, to;
};
vector<B>e [200001];
int main() {
	long long n,m;
	while (cin >> n>>m&&n != 0||m!=0) {
		for (int i = 0; i <= n; i++) {
			a[i] = inf;
			e[i].clear();
		}
		for (int i = 0; i < m; i++) {
			int a, b, c;
			cin >> a >> b >> c;
			e[b].push_back(B{ a,c });
		}
		a[1] = 0;
		priority_queue<P, vector<P>, greater<P>>p;
		p.push(P{ 0,1 });
		while (!p.empty()) {
			P t = p.top(); p.pop();
			if (a[t.pos] != inf) {
				for (int i = 0; i < (int)e[t.pos].size(); i++) {
					if (a[e[t.pos][i].to] > a[t.pos] + e[t.pos][i].time) {
						a[e[t.pos][i].to] = a[t.pos] + e[t.pos][i].time;
						p.push(P{ a[e[t.pos][i].to],e[t.pos][i].to });
					}
				}
			}
		}
		int sum = 0;
		for (int i = 1; i <= n; i++) {
			if (a[i] != inf) sum++;
		}
		cout << sum << endl;
	}
}