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<iostream>
using namespace std;
typedef struct
{
	long t;
	int s, d;
}Data;
int main()
{
	int N, M;
	while (cin >> N >> M && N != 0 || M != 0)
	{
		Data data[20000];
		for (int i = 0; i < M; i++)
		{
			cin >> data[i].t >> data[i].s >> data[i].d;
			data[i].s--;
			data[i].d--;
		}

		for (int i = 0; i < M - 1; i++)
		{
			for (int j = i + 1; j < M; j++)
			{
				if (data[i].t > data[j].t)
				{
					Data tmp = data[i];
					data[i] = data[j];
					data[j] = tmp;
				}
			}
		}

		bool infected[20000];
		for (int i = 0; i < N; i++)infected[i] = false;
		infected[0] = true;
		for (int i = 0; i < M; i++)
		{
			if (infected[data[i].s])
			{
				infected[data[i].d] = true;
			}
		}

		int ans = 0;
		for (int i = 0; i < N; i++)
		{
			if (infected[i])ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

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<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
int stoi(string x){stringstream ss;ss<<x;int tmp;ss>>tmp;return tmp;}
string itos(int x){stringstream ss;ss<<x;return ss.str();}

#define P pair<int,int>
bool G[30000];
vector<pair<int,P> >ta;
int main(){
	int n,m;
while(true){
	cin>>n>>m;
	if(n==0&&m==0)break;
for(int i=0;i<m;i++){
int a,b,c;
cin>>a>>b>>c;
ta.push_back(pair<int,P>(a,P(b,c)));
}
sort(ta.begin(),ta.end());
G[1]=1;
for(int i=0;i<m;i++){
	int a=ta[i].first,b=ta[i].second.first,c=ta[i].second.second;
	if(G[b]==1)G[c]=1;
}
int ans=0;
for(int i=0;i<=n;i++)if(G[i])ans++;
cout<<ans<<endl;
fill(G,G+30000,0);
ta.clear();
}
return 0;
}

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

typedef struct{
  int t;
  int s;
  int d;
}Data;

bool operator<(Data d1,Data d2){
  return (d1.t < d2.t);
}

int main(){
  int n,m;
  while(cin>>n>>m,n){
    vector<Data> v(m);
    for(int i=0;i<m;i++){
      cin>>v[i].t>>v[i].s>>v[i].d;
      v[i].s--;
      v[i].d--;
    }
    sort(v.begin(),v.end());
    vector<int> infected(n,0);
    int cnt=1;
    infected[0]=-1;

    for(int i=0;i<m;i++){
      if(infected[v[i].s]!=0 && infected[v[i].s]!=v[i].t){
	infected[v[i].d]=v[i].t;
	cnt++;
      }
    }
    cout<<cnt<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define pb(a) push_back(a)
#define pr(a) cout<<(a)<<endl
#define PR(a,b) cout<<(a)<<" "<<(b)<<endl
#define R cin>>
#define F first
#define S second
#define ll long long
bool check(int n,int m,int x,int y){return (x<0||x>=n||y<0||y>=m)?false:true;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
typedef pair<int,int> P;
typedef pair<int,P> P2;

vector<int> v[20010];
bool u[20010];

int main() {
  int n,m;
  while(R n >> m && n) {
    rep(i,20010) {v[i].clear();u[i]=false;}
    P2 a[m];
    rep(i,m) {
      int x,y,z;
      R x >> y >> z;
      a[i]=P2(x,P(y,z));
    }
    sort(a,a+m);
    u[1]=true;
    rep(i,m) {
      if(u[a[i].S.F]) u[a[i].S.S]=true;
    }
    int ans=0;
    REP(i,1,n+1) if(u[i]) ans++;
    pr(ans);
  }
  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;
struct P {
	long long time, from, to;
};
bool operator<(P a, P b) { return a.time < b.time; }
bool operator>(P a, P b) { return a.time > b.time; }
bool a[20001];
int main() {
	long long n, m;
	while (cin >> n >> m&&n != 0 && m != 0) {
		for (long long i = 1; i <= n; i++) a[i] = false;
		a[1] = true;
		priority_queue<P, vector<P>, greater<P>>p;
		for (long long i = 0; i < m; i++) {
			long long t, s, d;
			cin >> t >> s >> d;
			p.push(P{ t,s,d });
		}
		long long sum = 1;
		while (!p.empty()) {
			P t = p.top(); p.pop();
			if (a[t.from]) {
				if (!a[t.to]) sum++;
				a[t.to] = true;
			}
		}
		cout << sum << endl;
	}
}

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

using namespace std;

int main(void)
{
	int n, m;
	while (cin >> n >> m, n && m){
		vector < pair <int, int> > data(m);
		pair <int, int> edge[20050];
		for (int i = 0; i < 20050; i++){
			edge[i].first = edge[i].second = -1;
		}
		int t, s, d;
		for (int i = 0; i < m; i++){
			cin >> t >> s >> d;
			data[i].first = t;
			data[i].second = i;
			edge[i].first = s;
			edge[i].second = d;
		}
		sort(data.begin(), data.end());

		bool infect[20050] = {false};
		infect[1] = true;
		for (int i = 0; i < m; i++){
			int from = edge[data[i].second].first;
			int goal = edge[data[i].second].second;
			if (infect[from]){
				infect[goal] = true;
				// cout << goal << " is infect" << endl;
			}
		}

		int ret = 0;
		for (int i = 0; i <= 20050; i++){
			if (infect[i]) ret++;
		}
		cout << ret << endl;
	}

	return 0;
}