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

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

int main()
{
	int N,M;
	while(scanf("%d%d", &N, &M), (N||M))
	{
		Pkt p[20000];
		for(int i=0; i<M; i++)
		{
			int t,s,d;
			scanf("%d%d%d",&t,&s,&d);
			s--; d--;
			p[i]=Pkt(t,s,d);
		}
		
		sort(p,p+M);
		
		bool infe[20000]={0};
		infe[0]=1;
		for(int i=0; i<M; i++)
		{
			if(!infe[p[i].s]) continue;
			infe[p[i].d]=1;
		}
		
		int cnt=0;
		for(int i=0; i<N; i++)
			if(infe[i]) cnt++;
			
		printf("%d\n", cnt);
	}
}

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]==0){
	infected[v[i].d]=v[i].t;
	cnt++;
      }
    }
    cout<<cnt<<endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m,n+m){
    int a,b,c,k[20001]={},s[22222][2];
    k[1]=1;
    for(int i=0;i<m;i++){
      cin>>a>>b>>c;
      s[a][0]=b;
      s[a][1]=c;
    }

    for(int i=1;i<=m;i++){
      if(k[s[i][0]]==1)k[s[i][1]]=1;
    }
    int ans=0;
    for(int i=1;i<=n;i++)ans+=k[i];
    cout<<ans<<endl;
  }
  return 0;
}

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

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

bool comp(const data &a, const data &b)
{
  return a.t < b.t;
}

int main()
{
  while(1){
    int N, M;
    cin >> N >> M;
    if(N == 0 && M == 0) break;
    vector<data> v(M);
    for(int i = 0; i < M; i++){
      cin >> v[i].t >> v[i].s >> v[i].d;
    }
    sort(v.begin(),v.end(),comp);
    vector<bool> c(N+1);
    fill(c.begin(),c.end(),false);
    c[1] = true;
    for(int i = 0; i < M; i++)
      if(c[v[i].s])
        c[v[i].d] = c[v[i].s];
    cout << count(c.begin(),c.end(),true) << endl;
  }
}

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

using namespace std;

struct Packet {
  int t, s, d;

  Packet() = default;
  Packet(int t, int s, int d): t(t), s(s), d(d) { }

  bool operator<(const Packet& p) const {
    return t < p.t;
  }
};

int main() {
  while (true) {    
    int N, M;
    cin >> N >> M;

    if (N + M == 0) {
      break;
    }

    bool infected[20001] = { true };

    vector<Packet> packet(M);
    for (int i = 0; i < M; i++) {
      int t, s, d;
      cin >> t >> s >> d;
      packet[i] = Packet(t, s - 1, d - 1);
    }
    sort(packet.begin(), packet.end());

    for (int i = 0; i < M; i++) {
      if (infected[packet[i].s]) {
        infected[packet[i].t] = true;
      }
    }

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

    cout << ans << endl;
  }

  return 0;
}

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

typedef pair<int,int> P;

int main ()
{
    int n, m;
    while (cin >> n >> m, n || m) {
        vector<pair<int,P> > data(m);
        vector<bool> v(n+1, false);
        v[1] = true;

        for (int i = 0; i < m; i++) {
            int t;
            cin >> t;
            P p;
            cin >> p.first >> p.second;
            data[i] = pair<int,P>(t,p);
        }

        sort(data.begin(), data.end());

        for (int i = 0; i < m; i++) {
            if (v[data[i].second.first]) v[data[i].second.second] = true;
        }

        int res = 0;
        for (auto i : v) {
            if (i) res++;
        }

        cout << res << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<sstream>
#include<queue>
#include<deque>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#define INF 2147483647
#define lli long long int
#define MOD 1000000007
#define pb push_back

using namespace std;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
int main() {
	while(1){
		int n,m; cin >> n >> m;
		if (n + m == 0) break;
		vi infected(n,0);
		infected[0] = 1;

		vector<pair<int ,pair<int,int>>> data;
		for (int i = 0; i < m; i++){
			int t,s,d; cin >> t >> s >> d;
			data.pb(make_pair(t,make_pair(s,d)));
		}
		sort(data.begin(),data.end());

		for (int i = 0; i < m; i++){
			if (infected[data[i].second.first-1] == 1){
				infected[data[i].second.second-1] = 1;
			}
		}
		int ans = 0;
		for (int i = 0; i < n; i++){
			ans += infected[i];
		}
		
		cout << ans << endl;


	}

	return 0;
}