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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define tm first
#define sm second.first
#define dm second.second

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int main(void){
    for(int n, m, res; cin >> n >> m, n; cout << res << endl){
        res = 1;
        
        vi infected(n + 1); infected[1] = 1;
        vector< pair<int, pii> > log(m);
        rep(i, m){
            cin >> log[i].tm >> log[i].sm >> log[i].dm;
        }

        sort(all(log));
        rep(i, m){
            if(infected[log[i].sm])
                infected[log[i].dm] = 1;
        }

        res = count(all(infected), 1);
    }

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  while(1){
    int n,m;
    cin>>n>>m;
    if(n==0 && m==0) break;
    int flag[20000]={0};
    pair<int,pair<int,int> > p[20000];
    rep(i,m){
      int t,s,d;
      cin>>t>>s>>d;
      s--;d--;
      p[i]=make_pair(t,make_pair(s,d));
    }
    sort(p,p+m);
    flag[0]++;
    int ans=1;
    rep(i,m){
      if(flag[p[i].scd.fst]){
	if(flag[p[i].scd.scd]==0){
	  flag[p[i].scd.scd]=1;
	  ans++;
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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<P> packets(N);
    vector<int> S(N), D(N);
    REP(i, M) {
      int t; cin >> t >> S[i] >> D[i]; S[i]--, D[i]--;
      packets[i] = P(t, i);
    }
    sort(ALL(packets));
    vector<bool> infected(N, false);
    infected[0] = true;
    for (P packet : packets) {
      int i = packet.second, s = S[i], d = D[i];
      infected[d] =  infected[d] | infected[s];
    }
    cout << accumulate(ALL(infected), 0) << endl;
  }

  return 0;
}

C++: 
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2155

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

struct Packet
{
	int time;
	int source;
	int dest;

	Packet(int t, int s, int d): time(t),source(s),dest(d){}
	
	bool operator<( const Packet &right ) const {
		return time < right.time;
	}
};

int main()
{
	int M,N;

	while(cin >> N >> M && N)
	{
		vector< Packet > packets;
		vector<int> PC( N, 0 ); 
		
		int T,S,D;
		rep(nth,M)
		{
			cin >> T >> S >> D;
			packets.push_back( Packet(T,S-1,D-1) );
		}

		sort(ALL(packets));

		
		PC[0] = 1;
		rep(i,M)
		{
			Packet p =  packets[i];
			if(PC[p.source]){ PC[p.dest] = PC[p.source]; }
		}

		int ans = accumulate(ALL(PC),0);
		cout << ans << endl;
	}
	return 0;
}

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

typedef struct InfectedComputer{
	int time;
	int s;
	int d;
	bool operator<(const InfectedComputer& right) const {
		return time < right.time;
	}
}IC;

int main(){
	int N, M, t, s, d;
	while(1){
		int count = 0;
		bool temp[20100] = {0,1};
		IC infe[20100];
		cin>>N>>M;
		if(!N&&!M)break;
		for(int i = 1; i <= M; i++)	cin>>infe[i].time>>infe[i].s>>infe[i].d;
		sort(infe,infe+M+1);
		for(int i = 1; i <= M; i++)if(temp[infe[i].s])temp[infe[i].d]=true;
		for(int i = 1; i <= N; i++)if(temp[i])count++;
		cout<<count<<endl;
	}
	return 0;
}