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 <bits/stdc++.h>

#define REP(i, n) for(int i = 0; i < (int) (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9+7

using namespace std;
bool infected[20000];

struct logs{
  int t, f, d;
  logs(int t, int f, int d) : t(t), f(f), d(d) {}
  logs() : t(INF), f(0), d(0) {}
  bool operator<(logs &x)const{
    if(t < x.t) return true;
    return false;
  }
};

logs data[20000];

int main(){
  int n, m;
  while(cin >> n >> m and n + m){
    memset(infected, 0, sizeof(infected));
    REP(i, 20000){
      data[i] = logs(INF, 0, 0);
    }
    REP(i, m){
      int t, s, d;
      cin >> t >> s >> d; s--; d--;
      data[i] = logs(t, s, d);
    }
    sort(data, data+n);
    infected[0] = true;
    REP(i, m){
      if(infected[data[i].f]) infected[data[i].t] = true;
      else infected[data[i].t] = false;
    }
    int res = 0;
    REP(i, n) if(infected[i]) res++;
    cout << res << endl;
  }
}

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

int main() {
    int N, M;
    while(cin >> N >> M, N) {
        vector<int> v(N, 0);
        v[0] = 1;
        vector<tuple<int, int, int>> r(M);
        for(int i=0; i<M; ++i) {
            int t, s, d;
            cin >> t >> s >> d;
            r[i] = make_tuple(t, s, d);
        }
        sort(r.begin(), r.end(), [](auto const& t1, auto const& t2) {
            return get<0>(t1) < get<0>(t2);
        });

        for(int i=0; i<r.size(); ++i) {
            if(v[get<2>(r[i])-1] != 1) {
                v[get<2>(r[i])-1] = v[get<1>(r[i])-1];
            }
        }
        int ret = 0;
        for(int i=0; i<v.size(); ++i) {
            if(v[i] == 1) ret++;
        }
        cout << ret << endl;
    }
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
typedef pair<int, pair<int, int>> p;
int main() {
	int n, m;
	while (cin >> n >> m, n, m) {
		bool b[20010] = {};
		b[1] = true;
		p a[20010];
		for (int i = 0; i < m; i++)cin >> a[i].first >> a[i].second.first >> a[i].second.second;
		sort(a, a + m);
		for (int i = 0; i < m; i++) 
			if (b[a[i].second.first])b[a[i].second.second] = true;
		int ans = 0;
		for (int i = 1; i <= n; i++)if (b[i])ans++;
		cout << ans << endl;
	}
}

C++: // 2017-02-21
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
using namespace std;

int main() {
	int n, m;
	while (cin >> n >> m, n) {
		vector<pair<int, pair<int, int>>> v;
		for (int i = 0; i < m; i++) {
			int t, s, d;
			cin >> t >> s >> d;
			v.push_back(make_pair(t, make_pair(s - 1, d - 1)));
		}
		sort(begin(v), end(v));
		bool a[20000] = {true};
		int c = 1;
		for (int i = 0; i < m; i++) {
			int s, d;
			s = v[i].second.first;
			d = v[i].second.second;
			if (a[s] && !a[d]) {
				a[d] = true;
				c++;
			}
		}
		cout << c << endl;
	}
	return 0;
}

C++: #include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n,m;
	while(cin>>n>>m,n||m){
		bool infect[n+1];
		rep(i,n+1)infect[i]=false;
		infect[1]=true;
		long long t,s,d,ans=1;
		rep(i,m){
			cin>>t>>s>>d;
			if(infect[s]){
				ans++;
				infect[d]=true;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <cassert>

using namespace std;

typedef long long ll;
typedef ll li;
typedef pair<int,int> PI;
#define EPS (1e-10L)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
void pkuassert(bool t){t=1/t;};

int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};


int n,m;

void solve(){
  vector<pair<PI,int> > in(n);
  rep(i,n) cin >> in[i].F.F >> in[i].F.S >> in[i].S;
  sort(ALL(in));
  int inf[m];
  memset(inf,0,sizeof(inf));
  inf[0]=1;
  FOR(it,in) inf[it->S-1] |= inf[it->F.S-1];
  int ans=0;
  rep(i,m) ans += inf[i];
  cout << ans << endl;
}


int main(int argc, char *argv[])
{
  while(cin >> m >> n && n|m) solve();
  return 0;
}