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 namespace std;

vector<long long int> v(20001);

int main(){
  int n,m,i;
  while(cin >> n >> m, n != 0 || m != 0) {
    int cnt = 1, data[20001][2] = {};
    int in[20001] = {};
    v.clear();
    in[1] = 1;
    for(i = 0; i < m; i++) {
      int t,s,g;
      cin >> t >> s >> g;
      data[t][0] = s;
      data[t][1] = g;
      v.push_back(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<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);
    int cnt = 1, data[20100][10] = {};
    int in[20100] = {};
    in[1] = 1;
    k = 0;
    for(i = 0; i < m; i++) {
      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[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 });
					}
				}
			}
		}
		int sum = 0;
		for (int i = 1; i <= n; i++) {
			if (a[i] != inf) sum++;
		}
		cout << sum << endl;
	}
}

C++: #include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

int main(void) {
  ll N, M;
  while(cin >> N >> M, N && M) {
    vector<vector<pll>> E(N);
    REP(i, 0, M) {
      ll t, s, d;
      cin >> t >> s >> d;
      s--;
      d--;
      E[s].push_back(pll(t, d));
    }

    vector<bool> used(N, false);
    priority_queue<pll> q;
    q.push(pll(0, 0));
    while(q.size()) {
      ll v = q.top().second, t = q.top().first;
      q.pop();

      if(used[v]) continue;
      used[v] = true;

      for(pll p : E[v]) {
        ll nv = p.second, nt = p.first;
        if(nt >= t) {
          q.push(pll(nt, nv));
        }
      }
    }

    ll ans = 0;
    REP(i, 0, N) if(used[i]) ans++;
    cout << ans << endl;
  }
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  while (1) {
    int N, M; cin >> N >> M;
    if (N == 0 and M == 0) break;
    vector<T> packets(N);
    REP(i, M) {
      int t, s, d; cin >> t >> s >> d; s--, d--;
      packets[i] = T(t, s, d);
    }
    sort(ALL(packets));
    vector<bool> infected(N, false);
    infected[0] = true;
    int ans = 1;
    for (T packet : packets) {
      int t, s, d; tie(t, s, d) = packet;
      if (infected[s] and not infected[d]) {
        infected[d] = true;
        ans++;
      }
    }
    cout << ans << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<algorithm>
#define MAX 20001
using namespace std;

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


int main(){
 
  int n,m;
  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0)break;
    Data data[m];
    bool node[n+1];
    for(int i = 0 ; i < m ; i++){
      cin >> data[i].t >> data[i].s >> data[i].d;
    }
    sort(data,data + m);
    for(int i = 0 ; i < n+1 ; i++)node[i] = false;
    node[1] = true;
    for(int i = 0 ;i < m ; i++){
      if(node[data[i].s])node[data[i].d] = true;
    }

    int cnt = 0 ;
    for(int i = 0 ; i < n+1 ; i++){
      if(node[i])cnt++;
    }
    cout << cnt << endl;
  }  
  return 0;
}

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

struct data{
  int s,d;
};

int main(){
  while(1){
    int n,m,f[N]={},cnt=1,t;
  data da[N];
  cin>>n>>m;
  if(n+m==0) break;
  f[1]=1;
  for(int i=0;i<m;i++) cin>>t,cin>>da[t].s>>da[t].d;
   
      for(int i=1;i<=m;i++){
      if(f[da[i].s]==1)f[da[i].d]=1;
      if(da[i].s==1)f[da[i].d]=1;
    }
    for(int i=2;i<=n;i++) if(f[i]==1)cnt++;
    cout<<cnt<<endl;
  }
 
  
  return 0;
}