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;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

void solve(int n,int m){
	int t,s,d;
	vb b(n,false);
	b[0]=true;
	vector<tlll> v(m);
	rep(i,m){
		cin>>t>>s>>d;
		t--;s--;d--;
		v[i]=tlll(t,s,d);
	}
	sort(all(v));
	rep(i,m){
		b[get<2>(v[i])]=b[get<2>(v[i])]|b[get<1>(v[i])];
	}
	int cnt=0;
	rep(i,n)if(b[i])cnt++;
	cout<<cnt<<endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;
	while(cin>>n>>m,n)solve(n,m);
}

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];

int dfs(int v, int t)
{
  if(visited[v]) return 0;
  visited[v] = true;
  int ret = 0;
  for(int i = 0; i < graph[v].size(); i++){
    if(t < graph[v][i].tim){
      ret += dfs(graph[v][i].to, graph[v][i].tim);
    }
  }
  return ret + 1;
}

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());
    int ans = 1;
    memset(visited, false, sizeof(visited));
    for(int i = 0; i < graph[0].size(); i++){
      visited[0] = false;
      ans += dfs(graph[0][i].to, graph[0][i].tim);
    }
    cout << ans << endl;
    for(int i = 0; i < N; i++) graph[i].clear();
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;main(){for(int N,M,i;cin>>N>>M,N;cout<<N<<endl){vector<int>v(N+1),s(M+1),d(M+1);for(i=0;i++<M;cin>>s[N]>>d[N])cin>>N;v[1]=N=1;for(i=0;i++<M;)if(v[s[i]])v[d[i]]=1&&v[d[i]]||N++;}}

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;
}

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

int N, M;

class Data {
public:
  int t, s, d;
};

Data data[21234];
bool infected[21234];

bool operator < (const Data& a, const Data& b) {
  return a.t < b.t;
}

int main() {

  while( std::cin >> N >> M, N != 0 and M != 0 ) {
    for(int i = 0; i < M; ++i) {
      std::cin >> data[i].t >> data[i].s >> data[i].d;
    }
    std::sort(data, data + M);
    for(int i = 1; i <= N; ++i) {
      infected[i] = false;
    }
    infected[1] = true;
    for(int i = 0; i < M; ++i) {
      for(int j = i; j < M; ++j) {
        if( data[i].t != data[j].t ) {
          for(int k1 = i; k1 < j; ++k1) {
            for(int k2 = i; k2 < j; ++k2) {
              infected[data[k2].d] |= infected[data[k2].s];
            }
          }
          i = j - 1;
          break;
        }
      }
    }
    for(int i = 0; i < M; ++i) {
      infected[data[i].d] |= infected[data[i].s];
    }
    int res = 0;
    for(int i = 1; i <= N; ++i) {
      if( infected[i] ) res += 1;
    }
    std::cout << res << std::endl;
  }  

  return 0;
}