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;
struct set{
  int t;
  int s;
  int d;
};
int main(){
  int n,m,i,j,cnt,source,destination,start,end[20001],flag;
  struct set data[20001];
  while(1){
    flag=0;
    for(i=1;i<20001;i++) end[i]=0;
    end[1]=1;
    cin >> n >> m;
    if(n==0&&m==0) break;
    if(m!=0){
      for(i=0;i<m;i++){
	cin >> data[i].t >> data[i].s >> data[i].d;
      }
      for(i=0;i<m;i++){
	for(j=1;j<m;j++){
	  if(data[i].t<data[i-1].t) swap(data[i],data[i-1]);
	}
      }
      for(i=0;i<m;i++){
	if(data[i].s==1||data[i].d==1){
	  source=data[i].s;
	  destination=data[i].d;
	  start=i+1;
	  flag=1;
	  break;
	}
      }
      if(flag==1){
	if(source==1){
	  end[data[i].d]=1;
	  cnt=2;
	}
	if(destination==1) cnt=1;
	for(i=start;i<m;i++){
	  if(end[data[i].s]==1&&end[data[i].d]==0){
	    cnt++;
	    end[data[i].d]=1;
	  }
	}
	cout << cnt << endl;
      }
      else cout << 1 << endl;
    }
    else cout << 1 << endl;
  }
  
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cmath>
#include <time.h>
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) ((c).rbegin(),(c).rend())
//#define sort(v,n) sort(v,v+n)
#define ll long long
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int n, m;
bool now[20001];

int main() {
	while (cin >> n >> m, n) {
		for (int i = 0; i < 20001; i++) {
			now[i] = 0;
		}
		now[1] = 1;
		vector<pair<int,pair<int,int>>> vp;
		for (int i = 0; i < m; i++) {
			int a, b, c; cin >> a >> b >> c;
			vp.push_back(pair<int, pair<int, int>>(a, pair<int, int>(b, c)));
		}
		sort(vp.begin(), vp.end());
		for (int i = 0; i < vp.size(); i++) {
			if (now[vp[i].second.first] == 1) {
				now[vp[i].second.second] = 1;
			}
		}
		int ans = 0;
		for (int i = 1; i <= n; i++) {
			if (now[i] == 1)ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <tuple>

using namespace std;
using ll = long long;


int main()
{
    while (true) {
        int N, M;
        cin >> N >> M;
        if (N == 0 and M == 0) {
            break;
        }
        vector<int> ng(N, false);
        ng[0] = true;
        vector<tuple<int, int, int>> pac(M);
        for (int i = 0; i < M; i++) {
            int t, s, d;
            cin >> t >> s >> d;
            s--, d--;
        }
        sort(pac.begin(), pac.end());
        for (const auto& p : pac) {
            const int from = get<1>(p);
            const int to = get<2>(p);
            if (ng[from]) {
                ng[to] = true;
            } else if (ng[to]) {
                ng[from] = true;
            }
        }
        cout << accumulate(ng.begin(), ng.end(), 0) << endl;
    }
    return 0;
}

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

using namespace std;

int main() {
	while( true ) {
		long long int N, M;
		cin >> N >> M;
		if( N==0&&M==0 ) {
			break;
		}
		vector<pair<int, pair<int, int>>>d(M);
		for( size_t i = 0; i < M; i++ ) {
			cin >> d[i].first >> d[i].second.first >> d[i].second.second;
		}
		sort( d.begin() , d.end());
		set<int>X;
		X.insert( 1 );
		for( size_t i = 0; i < M; i++ ) {
			if( X.count(d[i].second.first) ) {
				X.insert( d[i].second.second );
			}
		}
		cout << X.size() << endl;
	}
}

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] == true){
			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;
}

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

using namespace std;

typedef pair<int, int> pii;
typedef pair<int, pii> pipii;

int main(){
	ios_base::sync_with_stdio(false);
	while(true){
		int n, m;
		cin >> n >> m;
		if(n == 0 && m == 0){ break; }
		vector<pipii> seq(m);
		for(int i = 0; i < m; ++i){
			int t, s, d;
			cin >> t >> s >> d;
			--s; --d;
			seq[i] = pipii(t, pii(s, d));
		}
		sort(seq.begin(), seq.end());
		vector<int> s(m), d(m);
		for(int i = 0; i < m; ++i){
			s[i] = seq[i].second.first;
			d[i] = seq[i].second.second;
		}
		vector<int> infect(n, -1);
		infect[0] = 0;
		for(int i = 0; i < m; ++i){
			if(infect[s[i]] >= 0){ infect[d[i]] = i; }
		}
		int answer = 0;
		for(int i = 0; i < n; ++i){
			if(infect[i] >= 0){ ++answer; }
		}
		cout << answer << endl;
	}
	return 0;
}