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>I don't know
#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();}
double ta[300][3];
bool used[300],tused[300];

	int n,m;
double ans=0;
double solve(int now){
double ret=0.0;
while(true){
	tused[now]=0;

	int next=0,f=0;
	for(int i=0;i<n;i++){
		if(tused[i]&&!f)next=i,f=1;
	}
	for(int i=0;i<n;i++){
	if(tused[i]){
		for(int j=0;j<3;j++)ret+=(ta[i][j]-ta[now][j])*(ta[i][j]-ta[now][j]);

		}
	}
	now=next;
	bool endf=1;
	for(int i=0;i<n;i++)if(tused[i])endf=0;
	if(endf)break;
}
return ret;
}
void  dfs(int h,int use){
	if(h==n){
	//for(int i=0;i<n;i++)cout<<used[i]<<" ";cout<<endl;
	if(use==m){
	int next=0;
	for(int i=n-1;i>=0;i--)if(used[i])next=i,tused[i]=used[i];
	ans=max(ans,solve(next));
	}
	return ;
	}
	used[h]=1;
	dfs(h+1,use+1);
	used[h]=0;
	dfs(h+1,use);
}
int main(){

	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)cin>>ta[i][0]>>ta[i][1]>>ta[i][2];
	dfs(0,0);
	printf("%.10f\n",ans);
	return 0;
}

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

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n,m;
  while(true){
    cin >> n >> m;
    if(n==0) break;
    bool infected[n+1];
    for(int i=2;i<n+1;i++) infected[i]=false;
    infected[1]=true;
    int s[m+1],d[m+1];
    vector<pair<int,int>> t;
    for(int i=1;i<=m;i++){
      int tmp;
      cin >> tmp >> s[i] >> d[i];
      t.push_back(make_pair(tmp,i));
    }
    sort(t.begin(),t.end());
    for(int i=0;i<m;i++){
      int idx=t[i].second;
      if(infected[s[idx]]) infected[d[idx]]=true;
    }
    int res=0;
    for(int i=1;i<=n;i++) if(infected[i]) res++;
    cout << res<< endl;
  }
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

class UFT {
private:
  vi data, rnk;

public:
  UFT(const int &size)
    : data(size), rnk(size) {
    iota(all(data), 0);
  }

  int root(const int &x) {
    return data[x] == x ? x : data[x] = root(data[x]);
  }

  bool same(const int &a, const int &b) {
    return root(a) == root(b);
  }

  void unite(int a, int b) {
    a = root(a), b = root(b);
    if (a == b) return;
    if (rnk[a] < rnk[b]) swap(a, b);
    data[b] = a;
    if (rnk[a] == rnk[b]) rnk[a]++;
  }
};

void solve() {
  int n, m;
  while (cin >> n >> m, n) {
    vector<tuple<int, int, int>> v;
    while (m--) {
      int t, s, d;
      cin >> t >> s >> d;
      v.emplace_back(t, --s, --d);
    }
    sort(all(v));
    UFT uf(n);
    rep(i, v.size()) {
      int s, d;
      tie(ignore, s, d) = v[i];
      if (uf.same(0, s)) uf.unite(0, d);
    }
    int c = 0;
    rep(i, n) c += uf.same(0, i);
    cout << c << endl;
  }
}

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

using namespace std;

int n, m;
bool bad[20001];

int main(){
    while (cin >> n >> m && n | m){
        vector<vector<int>> record(m, vector<int>(3));
        for (int i = 0; i < m; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                cin >> record[i][j];
            }
        }
        sort(record.begin(), record.end());
        memset(bad, 0, sizeof(bad));
        bad[1] = true;
        for (auto & r : record){
            bad[r[2]] |= bad[r[1]];
        }
        cout << count_if(bad + 1, bad + 1 + n, [](bool t){ return t; }) << endl;
    }
}

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