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<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,b,n) for(int i=b;i<n;i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
/*union-find*/
const int MAX_N =20010;
int parent[MAX_N];//parent[x]=xの時xが根である
int rank[MAX_N];
void init(int V){
	for(int i= 0;i < V;i++){
		parent[i] = i;
		rank[i] =0;
	}
}

int find(int x){
	if(parent[x] == x)
		return x;
	else{
		return find(parent[x]);
	}
}

void unit(int x,int y){
	x = find(x);
	y = find(y);
	if(x == y)
		return;
	if(rank[x] < rank[y]){
		parent[x] = y;
	}
	else{
		parent[y] = x;
		if(rank[x] == rank[y])
			rank[x]++;
	}
}

bool same(int x,int y){
	return find(x) == find(y);
}
typedef pair<ll,pii> P;
int main(){
	int N,M;
	while(cin>>N>>M,N||M){
		init(N+1);
		priority_queue<P,vector<P>,greater<P> > que;
		for(int i = 0;i < M;i++){
			int t,s,d;
			cin>>t>>s>>d;
			que.push(P(t,pii(s,d)));
		}
		/*cout <<que.top().first<<" "<<que.top().second.first<<" "<<que.top().second.second<<endl;*/
		while(!que.empty()){
			if(que.top().second.first==1){
				unit(1,que.top().second.second);
			}else if(same(1,que.top().second.first)){
				unit(que.top().second.first,que.top().second.second);
			}
			que.pop();
		}
		int cnt = 0;
		for(int i = 1;i <=N;i++){
			if(same(1,i)){
				cnt++;
			}
		}
		cout <<cnt<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
struct E{
	int t,a,b;
	bool operator<(E a)
	{
		return t<a.t;
	}
};
int n,m;
main()
{
	while(cin>>n>>m,n)
	{
		bool C[22222]={};
		E a[22222];
		C[1]=1;
		for(int i=0;i<m;i++)
		{
			int t,x,y;cin>>t>>x>>y;
			a[i].t=t,a[i].a=x,a[i].b=y;
		}
		sort(a,a+m);
		int cnt=1;
		for(int i=0;i<m;i++)
		{
			if(!C[a[i].a])continue;
			cnt+=!C[a[i].b];
			C[a[i].b]=1;
		}
		cout<<cnt<<endl;
	}
}

C++: #include<bits/stdc++.h>
#define N 20001
using namespace std;
 
struct data{
  int t,s,d;
};
 
int main(){
  while(1){
  int n,m,f[N]={},cnt=1;
  data da[N];
  cin>>n>>m;
  if(n+m==0) break;
  f[1]=1;
  for(int i=0;i<m;i++)cin>>da[i].t>>da[i].s>>da[i].d;
   
    for(int i=0;i<m-1;i++)
    for(int j=m-1;j>=i;j--)
    if(da[j].t<da[j-1].t)swap(da[j],da[j-1]);
         
    for(int i=0;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;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

const int MAX_N = 22222;
int N, M;
bool flag[MAX_N];
struct _data{int t, s, d;};

inline bool operator < (const _data& x, const _data& y){ return x.t < y.t; }

int main()
{
  while(cin >> N >> M, N){
    rep(i, N) flag[i] = false;
    vector<_data> data(M);

    rep(i, M) cin >> data[i].t >> data[i].s >> data[i].d;
    sort(ALL(data));

    flag[0] = true;
    rep(i, M) flag[data[i].d - 1] |= flag[data[i].s - 1];

    int res = 0;
    rep(i, N) if(flag[i]) res += 1;

    cout << res << endl;
  }

  return 0;
}

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

typedef pair<long long, long long> P;
typedef pair<long long, P> PP;

void solve(int n, int m){
	vector<PP> v;
	for(int i=0; i<m; ++i){
		int t, s, d;
		cin >> t >> s >> d;
		v.push_back(PP(t, P(s, d)));
	}
	sort(v.begin(), v.end());
	bool a[20010] = {};
	a[1] = true;
	for(int i=0; i<m; ++i)
		a[v[i].second.second] |= a[v[i].second.first];
	int res = 0;
	for(int i=1; i<=n; ++i)
		if(a[i])
			++res;
	cout << res << "\n";
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	while(1){
		int n, m;
		cin >> n >> m;
		if(n == 0 && m == 0) return 0;
		solve(n, m);
	}
}