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;

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;

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

const int nmax=20010;
bool infected[nmax];


int main(void){
	int n,m;
	while(cin >> n >> m){
		if(n==0)
			break;
		rep(i,nmax) infected[i]=false;
		infected[1]=true;
		vector<tuple<int,int,int>> data;

		rep(i,m){
			int t,s,d;
			cin >> t >> s >> d;
			data.push_back(make_tuple(t,s,d));
		}
		sort(data.begin(),data.end());
		rep(i,data.size()){
			int t,s,d;
			tie(t,s,d)=data[i];
			if(infected[s])
				infected[d]=true;
		}
		int ans=0;
		range(i,1,n+1) ans+=infected[i];
		cout << ans << endl;
	}
	return 0;
}

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

typedef ostringstream OSS;
typedef istringstream ISS;

typedef long long LL;
typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<PII> VPII;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x) (x).begin(),(x).end()
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define rep(i, N) for (int i = 0; i < (N); i++)
#define rep2(i, j, N, M) rep(i, N) rep(j, M)
#define rep3(i, j, k, N, M, L) rep(i, N) rep(j, M) rep(k, L)
#define REP(i, init, N) for (int i = (init); i < (N); i++)

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a) { OSS oss; oss << a; return oss.str(); };

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int N, M;

vector<pair<int, PII>> packets;

int solve() {
    VB bads(N);
    bads[0] = true;

    sort(ALL(packets));

    for (auto &p : packets) {
        bads[p.snd.snd] = bads[p.snd.snd] | bads[p.snd.fst];
    }

    return count(ALL(bads), true);
}

int main(void) {
    while (cin >> N >> M, N) {
        packets.clear();
        rep(i, M) {
            int t, s, d;
            cin >> t >> s >> d;
            --s; --d;
            packets.PB(MP(t, MP(s, d)));
        }

        cout << solve() << endl;
    }

	return 0;
}

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

using namespace std;

struct edge{
  int to, tim;
  edge(){}
  edge(int to, int tim):to(to), tim(tim){}
  bool operator < (const edge& e) const {
    return tim != e.tim ? tim < e.tim : to < e.to;
  }
};

vector< vector<edge> > graph(32768);
bool visited[32768];

typedef pair<int, int> P;

int bfs(int v, int t)
{
  priority_queue<P, vector<P>, greater<P> > que;
  que.push(P(t, v));
  int ret = 0;
  while(!que.empty()){
    int now = que.top().second, tim = que.top().first; que.pop();
    if(visited[now]) continue;
    visited[now] = true;
    ret++;
    for(int i = 0; i < graph[now].size(); i++){
      if(tim < graph[now][i].tim){
	que.push(P(graph[now][i].tim, graph[now][i].to));
      }
    }
  }
  return ret;
}

int main()
{
  int N, M;
  while(cin >> N >> M, N || M){
    graph.resize(N + 1);
    while(M--){
      int t, s, d;
      cin >> t >> s >> d;
      s--, d--;
      graph[s].push_back(edge(d, t));
    }
    for(int i = 0; i < N; i++) sort(graph[i].begin(), graph[i].end());
    memset(visited, false, sizeof(visited));
    cout << bfs(0, 0) << endl;
    for(int i = 0; i < N; i++) graph[i].clear();
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	long long n,m;
	while(cin>>n>>m,n){
		long long a[n+1]={0},b[m+1][2],t,s=0;
		a[1]=1;
		r(i,m){
			cin>>t;
			cin>>b[t][0]>>b[t][1];
		}
		r(i,m+1)if(a[b[i+1][0]])a[b[i+1][1]]=1;
		r(i,n+1)if(a[i+1])s++;
		cout<<s<<endl;
	}
}

C++: #include <iostream>
#include <queue>
#include <algorithm>
#include <tuple>
using namespace std;
using T = tuple<int,int,int>;
bool isInfected[20000];
vector<T> V;

int main(){
    int N,M;
    while(cin>>N>>M,N){
        V.clear();
        for(int i=0;i<M;i++){
            int t,s,d;
            cin>>t>>s>>d;
            V.emplace_back(t,s-1,d-1);
        }
        fill(isInfected,isInfected+20000,false);
        isInfected[0]=true;
        for(auto v:V){
            int t,s,d;
            tie(t,s,d)=v;
            if(isInfected[s])isInfected[d]=true;
        }

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