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++: #define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	for (;;) {
		int N, M; cin >> N >> M;
		if (N == 0) break;
		vector< pair<int, i_i> > v(M);
		for (int i = 0; i < M; i++) {
			int t, s, d; cin >> t >> s >> d;
			s--; d--;
			v[i] = make_pair(t, i_i(s, d));
		}
		sort(v.begin(), v.end());
		vector<bool> a(N);
		a[0] = true;
		for (int i = 0; i < M; i++) {
			int s = v[i].second.first, t = v[i].second.second;
			a[t] = a[t] || a[s];
		}
		int cnt = 0;
		for (int i = 0; i < N; i++)
			cnt += a[i];
		cout << cnt << endl;
	}
}

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

using namespace std;

int main(){
  long long int n,m,i, k;
  while(cin >> n >> m, n != 0 || m != 0) {
    vector<long long int> v(20100,0);
    long long int cnt = 1, data[20100][10] = {};
    long long int in[20100] = {};
    in[1] = 1;
    k = 0;
    for(i = 0; i < m; i++) {
      long long int t,s,g;
      cin >> t >> s >> g;
      data[t][0] = s;
      data[t][1] = g;
      v[k++] = t;
    }
    sort(v.begin(), v.begin() + m);
    for(i = 0; i < m; 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<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 = 1000000000;
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;
	}
}

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 <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;

int N,M;

class List{
public:
	int t;
	int s,d;
	bool operator< (const List &opp) const {
		return t<opp.t;
	}
};

main(){
	int i,j;
	while(cin >> N >> M, N){
		int Infected[20002];
		vector<List> list(M);
		for(i=1;i<=N;i++) Infected[i] = 0;
		for(i=0;i<M;i++) cin >> list[i].t >> list[i].s >> list[i].d;
		sort(list.begin(), list.end());
		Infected[1] = 1;
		int ans = 1;
		for(i=0;i<M;i++){
			if(Infected[list[i].s] && !Infected[list[i].d]){
				Infected[list[i].d] = 1;
				ans ++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

struct flow{
    int t,s,d;
    flow(int t,int s,int d):t(t),s(s),d(d){}
    bool operator<(const flow &rhs) const{
        return t<rhs.t;
    }
};

const int MAX_N=2e4+10;

int N,M,t,s,d,ans;
vector<flow> fs;
vector<int> infected(MAX_N);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> N >> M,N){
        fs.clear();
        for (int i=0;i<M;++i){
            cin >> t >> s >> d;
            fs.emplace_back(t,--s,--d);
        }
        sort(fs.begin(),fs.end());
        fill(infected.begin(),infected.end(),0);
        infected[0]=1;
        for (int i=0;i<M;++i){
            if (infected[fs[i].s]) infected[fs[i].d]=1;
        }
        ans=0;
        for (int i=0;i<N;++i) ans+=infected[i];
        cout << ans << '\n';
    }
}

C++: #include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	long long n,m;
	while(cin>>n>>m,n){
		long long a[n+1]={0},b[m+1][2]={0},t,s=0;
		a[1]=1;
		r(i,m){
			cin>>t;
			cin>>b[t][0]>>b[t][1];
		}
		r(i,m+1)if(a[b[i][0]])a[b[i][1]]=1;
		r(i,n+1)if(a[i])s++;
		cout<<s<<endl;
	}
}