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;

struct packet {
    int time, src, dst;
};

bool operator<(const packet& a, const packet& b)
{
    return a.time<b.time;
}

int main()
{
    int n, m;
    while(cin >> n >> m, n|m)
    {
        set<int> infected;
        infected.insert(1);
        packet ps[m];
        for(int i=0; i<m; i++)
        {
            cin >> ps[i].time >> ps[i].src >> ps[i].dst;
        }
        sort(ps, ps+m);
        for(int i=0; i<m; i++)
        {
            if(infected.find(ps[i].src)!=infected.end())
            {
                infected.insert(ps[i].dst);
            }
        }
        cout << infected.size() << endl;
    }

}

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]){
                int d = vec[i].second.second;
                if(infected[d]) continue;
                infected[d] = true;
                res++;
            }
        }
        cout << res<< endl;
    }

    return 0;
}

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

class Flow{
public:
    int t,s,d;
    bool operator<(const Flow &f){
        return f.t>this->t;
    }
};

int main(){
    int n,m;
    while(cin>>n>>m&&!(n==0&&m==0)){
        vector<Flow> v;
        for(int i = 0; i < m; i++){
            Flow f;
            cin>>f.t>>f.s>>f.d;
            v.push_back(f);
        }
        sort(v.begin(),v.end());
        int p=1;
        for(int i = 0; i < v.size(); i++){
            if(v[i].s==p){
                p=v[i].d;
            }
        }
        cout<<p<<endl;
    }
    return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct P{
	int t;
	int s;
	int d;
};

int cmp(const void *a,const void *b){
	struct P *tmp1 = (struct P *)a;
	struct P *tmp2 = (struct P *)b;
	return tmp1->t - tmp2->t;
}

int main(void){
	int n, m, count, i, j, p[20000];
	struct P data[20000];
	while(1){
		scanf("%d%d",&n,&m);
		if(n == 0 && m == 0)
			break;
		memset(p,0,sizeof(p));
		p[0] = 1;
		for(i = 0;i < m;i++)
			scanf("%d%d%d",&data[i].t,&data[i].s,&data[i].d);
		qsort(data,m,sizeof(data),cmp);
		for(i = 0;i < m;i++){
			if(p[data[i].s - 1])
				p[data[i].d - 1] = 1;
		}
		count = 0;
		for(i = 0;i < n;i++)
			if(p[i]) count++;
		printf("%d\n",count);
	}
	return 0;
}

C++: 
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cassert>
#include <iomanip>

using namespace std;

#define pb push_back
typedef long long ll;
typedef complex<int> P;

struct st{
	ll t;
	int s;
	int d;
	
	st(){}
	st(ll t,int s,int d): t(t), s(s), d(d){}
	
	bool operator< (const st &s) const{
		return this->t < s.t;
	}
};

bool solve(){
	int n, m;
	cin>> n>> m;
	if(n==0 && m==0) return false;
	
	vector<st> vst;
	for(int i=0;i<m;i++){
		ll t; int s, d;
		cin>> t>> s>> d;
		st tmp(t,s-1,d-1);
		vst.pb(tmp);
	}
	sort(vst.begin(), vst.end());
	
	vector<bool> com(n);
	fill(com.begin(), com.end(), false);
	com[0] = true;
	for(int i=0;i<m;i++){
		if(com[vst[i].s]) com[vst[i].d] = true;
	}
	
	cout<< count(com.begin(), com.end(), true)<< endl;
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	
	while(solve());

	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, m;
    
    while (scanf("%d %d", &n, &m) && n){
        int inf[20001] = {0};
        pair<int, pair<int, int> > log[20000];
        
        for (int i = 0; i < m; i++){
            int a, b, c;
            scanf("%d %d %d", &a, &b, &c);
            log[i] = make_pair(a, make_pair(b, c));
        }
        
        sort(log, log + m);
        
        inf[1] = 1;
        for (int i = 0; i < m; i++){
            if (inf[log[i].second.first]) inf[log[i].second.second] = 1;
        }
        
        int ans = 0;
        for (int i = 1; i <= n; i++) ans += inf[i];
        
        printf("%d\n", ans);
    }
    
    return (0);
}

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

using namespace std;

struct send
{
	int s;
	int d;
};

int main(void)
{
	int n,m;
	int i1;
	int t;
	int count;

	while(1){
		cin>>n>>m;
		if(n+m==0) break;

		map<int,send> data;
		send sd;
		vector<int> infe(n+1,0);
		infe[1]=1;
		count=1;

		for(i1=0;i1<m;i1++){
			cin>>t>>sd.s>>sd.d;
			data[t]=sd;
		}

		for(map<int,send >::iterator it=data.begin(); it!=data.end();it++){
			if(infe[(*it).second.s]==1 && infe[(*it).second.d]==0) {
				count++;
				infe[(*it).second.d]=1;
			}
		}
		cout<<count<<endl;
	}
	return 0;
}