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>
using namespace std;

#define int long long

signed main() {
  int N, M;
  while ( cin >> N >> M, N ) {
    vector<pair<int, pair<int, int> > > logs(M);
    for ( int i = 0; i < M; i++ ) {
      cin >> logs[i].first >> logs[i].second.first >> logs[i].second.second;      
    }
    
    sort(logs.begin(), logs.end());

    bool infected[20000] = {};
    infected[0] = true;
    for ( int i = 0; i < M; i++ ) {
      auto path = logs[i].second;
      int s = path.first, t = path.second;
      s--; t--;
      if ( infected[s] ) infected[t] = true;
    }

    int ans = 0;
    for ( int i = 0; i < N; i++ ) ans += infected[i];
    cout << ans << endl;
  }
  
  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )
#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

struct Event
{
	int t, s, d;
	Event( int t, int s, int d ) : t( t ), s( s ), d( d )
	{
		return;
	}

	bool operator < ( const Event &a ) const
	{
		return t < a.t;
	}
};

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

	for ( int n, m; cin >> n >> m, n | m; )
	{
		vector<Event> events;

		REP( i, 0, m )
		{
			int t, s, d;
			cin >> t >> s >> d;
			events.PB( Event( t, s - 1, d - 1 ) );
		}
		sort( ALL( events ) );

		VI infected( n );
		infected[0] = 1;
		FOR( e, events )
		{
			infected[ e.d ] |= infected[ e.s ];
		}

		cout << count( ALL( infected ), 1 ) << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

class C{
  public:
    int a, b, t;
    C(){}
    bool operator < (const C &c) const { return t < c.t; }
};

int main() {
  int N, M;
  while(cin >>N >>M && (N || M)){
    vector<C> v(M);
    REP(i, M){
      cin >>v[i].t >>v[i].a >>v[i].b;
      --v[i].a; --v[i].b;
    }
    SORT(v);
    vector<bool> f(N, 0);
    f[0] = 1;
    REP(i, M) if(f[v[i].a]) f[v[i].b] = 1;
    int ans = 0;
    REP(i, N) if(f[i]) ++ans;
    cout <<ans <<endl;
  }
  return 0;
}

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

using namespace std;

int main(int argc, char const *argv[])
{
	int n,m;
	int t,s,d;
	int cnt;

	while(1){
		cin>>n>>m;
		if(n+m==0) break;

		map<int,pair<int,int> > mp;
		vector<bool> v(n);

		for(int i1=0;i1<n;i1++) v[i1]=false;
		v[0]=true;

		for(int i1=0;i1<m;i1++){
			cin>>t>>s>>d;
			mp[t]=make_pair(s-1,d-1);
		}

		cnt=1;
		for(map<int,pair<int,int> >::iterator it=mp.begin();it!=mp.end();it++){
			if(v[(*it).second.first]) {
				v[(*it).second.second]=true;
				cnt++;
			}
		}
		cout<<cnt<<endl;
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
class packet {
public:
	int t, s, d;
	bool operator<(const packet &other) {
		return this->t < other.t;
	}
};
signed main() {
	int n, m;
	while (cin >> n >> m, n&&m) {
		vector<bool>v(n, false); v[0] = true;
		vector<packet>p(m);
		rep(i, 0, m) {
			cin >> p[i].t >> p[i].s >> p[i].d;
			p[i].s--; p[i].d--;
		}
		sort(p.begin(), p.end());
		rep(i, 0, m) {
			if (v[p[i].s] == true)v[p[i].d] = true;
		}
		cout << accumulate(v.begin(), v.end(), 0) << endl;
	}
	return 0;
}