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>
#include <vector>
#include <algorithm>

using std::cin;
using std::cout;
using std::endl;

struct data_t {
	int time;
	int sent;
	int res;

	bool operator<(const data_t& right) const {
		return ( time == right.time ) || ( time < right.time );
	}
};

int main(void) {
	int N,M;
	cin >> N;
	cin >> M;

	while (N != 0 || M != 0) {
		std::vector<data_t> record(M);

		for (int i = 0; i < M; i++) {
			cin >> record[i].time;
			cin >> record[i].sent;
			cin >> record[i].res;
		}

		std::sort(record.begin(), record.end());

		std::vector<bool> infected(N, false);
		infected[0] = true;
		int count = 1;

		for (int i = 0; i < M; i++) {
			if (infected[record[i].sent-1]) {
				if (!(infected[record[i].res-1])) {
					infected[record[i].res-1] = true;
					count++;
				}
			}
		}
		cout << count << endl;
		cin >> N;
		cin >> M;
	}

	return 0;
}

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

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

int main()
{
  int n,m,tmp,sum;
  struct data tsd[20001];

  for(;;){
    cin>>n>>m;
    if(!(n|m)) break;
    int inf[20001]={0};
    inf[0]=1;
    for(int i=0;i<m;i++)
      cin>>tsd[i].t>>tsd[i].s>>tsd[i].d;
    for(int i=0;i<m-1;i++)
      for(int j=0;j<m-1;j++)
	if(tsd[j].t>tsd[j+1].t){
	  tmp=tsd[j].t; tsd[j].t=tsd[j+1].t; tsd[j+1].t=tmp;
	  tmp=tsd[j].s; tsd[j].s=tsd[j+1].s; tsd[j+1].s=tmp;
	  tmp=tsd[j].d; tsd[j].d=tsd[j+1].d; tsd[j+1].d=tmp;
	}
    sum=1;
    for(int i=0;i<m;i++)
      if(inf[tsd[i].s-1]&&!inf[tsd[i].d-1]){
	inf[tsd[i].d-1]=1; sum++;
      }
    cout<<sum<<endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)

int main(){
	while(1){
		int n,m;
		cin>>n>>m;
		if(n==0&&m==0) break;
		tuple<int,int,int> li[20000];
		lp(i,m){
			int a,b,c;
			cin>>a>>b>>c;
			li[i]=make_tuple(a,b,c);
		}
		sort(li,li+m);
		set<int> inflist;
		inflist.clear();
		inflist.insert(1);
		int count=1;
		lp(i,m){
			int a,b;
			a=get<1>(li[i]);
			b=get<2>(li[i]);
			decltype(inflist)::iterator it=inflist.find(a);
			if(it!=inflist.end()){
				it=inflist.find(b);
				if(it==inflist.end()){
					inflist.insert(b);
					count++;
				}
			}
		}
		cout<<count<<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[200001];
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 });
					}
				}
			}
		}
		long long sum = 0;
		for (int  i = 1; i <= n; i++) {
			if (a[i] != inf) sum++;
		}
		cout << sum << endl;
	}
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;
typedef pair<int, pair<int, int> > P;

const int MAX_M = 20202;

void solve(int n, int m) {
    vector<P> v(m);
    for (int i = 0; i < m; i++) {
        cin >> v[i].first >> v[i].second.first >> v[i].second.second;
    }
    sort(v.begin(), v.end());
    vector<bool> is_infect(n, false);
    is_infect[0] = true;
    for (int i = 0; i < m; i++) {
        if (is_infect[v[i].second.first - 1]) {
            is_infect[v[i].second.second - 1] = true;
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (is_infect[i]) ans++;
    }
    cout << ans << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    while (true) {
        cin >> N >> M;
        if (N == 0 && M == 0) break;
        solve(N, M);
    }
    return 0;
}

C++: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

struct Info{
	bool operator<(const struct Info &arg) const{
		return t < arg.t;
	};
	Info(){
		t = from = to = 0;
	}
	int t,from,to;
};

void func(int N, int M){
	bool table[N+1];
	table[1] = false;
	for(int i = 2; i <= N; i++)table[i] = true;

	Info info[M];

	for(int i = 0; i < M; i++){
		scanf("%d %d %d",&info[i].t,&info[i].from,&info[i].to);
	}

	sort(info,info+M);

	int count = 1;

	for(int i = 0; i < M; i++){
		if(table[info[i].from] == false){
			table[info[i].to] = false;
			count++;
		}
	}

	printf("%d\n",count);

}

int main(){

	int N,M;

	while(true){
		scanf("%d %d",&N,&M);
		if(N == 0 && M == 0)break;

		func(N,M);

	}

	return 0;
}