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 <iostream>
#include <numeric>
#include <tuple>
#include <vector>

using namespace std;

int main()
{
    while (true) {
        int n, m;
        cin >> n >> m;
        if (n == 0 && m == 0) {
            return 0;
        }

        vector<tuple<int, int, int>> v;
        for (int i = 0; i < m; ++i) {
            int t, s, d;
            cin >> t >> s >> d;
            v.emplace_back(t, s, d);
        }
        sort(begin(v), end(v), [](const auto& a, const auto& b) {
            return get<0>(a) < get<0>(b);
        });
        vector<bool> states(n, false);
        states[0] = true;
        for (auto&& message : v) {
            int s, d;
            tie(ignore, s, d) = message;
            if (states[s - 1]) {
                states[d - 1] = true;
            }
        }
        cout << accumulate(begin(states), end(states), 0, [](int z, bool b) {
            return b ? z + 1 : z;
        }) << endl;
    }
}

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

typedef long long ll;
typedef struct DATA{
  ll t;
  int s, d;
}data;

data make_d(ll a, int b, int c){
  data ret;
  ret.t=a;
  ret.s=b;
  ret.d=c;
  return ret;
}

bool comp(const data &a, const data &b){
  return a.t<b.t;
}

int N, M;
int flag[20001];

int main(){
  while(cin>>N>>M, !(N==0&&M==0)){
    vector<data> v;
    memset(flag, 0, sizeof(flag));
    for(int i=0; i<M; i++){
      ll tmp1;
      int tmp2, tmp3;
      cin>>tmp1>>tmp2>>tmp3;
      v.push_back(make_d(tmp1, tmp2, tmp3));
    }
    sort(v.begin(), v.end(), comp);
    flag[1]=1;
    int cnt=1;
    for(int i=0; i<M; i++)
      if(flag[v[i].s]==1){
	flag[v[i].d]=1;
	cnt++;
      }
    cout<<cnt<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

typedef map<int, pair<int, int> > Packet;

int main() {
    while (true) {
        int n, m;
        cin >> n >> m;
        if ((n | m) == 0) {
            break;
        }
        Packet packets;
        for (int i = 0; i < m; i++) {
            int t, s, d;
            cin >> t >> s >> d;
            packets.insert(make_pair(t, make_pair(s, d)));
        }
        vector<bool> isInfected(n + 1);
        fill(isInfected.begin(), isInfected.end(), false);
        isInfected[1] = true;
        int infectedNum = 1;
        for (Packet::iterator it = packets.begin(); it != packets.end(); it++) {
            if (isInfected[it->second.first] == true && isInfected[it->second.second] == false) {
                isInfected[it->second.second] = true;
                infectedNum++;
            }
        }
        cout << infectedNum << endl;
    }
}

C++: #include <bits/stdc++.h> // {{{
// clang-format off
#define ARG4(_1, _2, _3, _4, ...) _4
#define rep(...) ARG4(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define REP(i, a) FOR(i, 0, a)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(...) ARG4(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define RREP(i, a) RFOR(i, 0, a)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (int)(a); --i)
#define ALL(c) (c).begin(), (c).end()
#define TEN(n) ((ll)(1e##n))
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define USE1(T) template <typename T> inline
#define USE2(T, U) template <typename T, typename U> inline
#define mygc(c) (c) = getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
 
template<typename T> using vec = std::vector<T>;
template<typename T> using withi = std::pair<T, int>;
using ll = long long;
USE2(T,U)bool chmax(T&x,U a){return x<a&&(x=a,1);}
USE2(T,U)bool chmin(T&x,U a){return a<x&&(x=a,1);}
USE1(T=int)T in(){T x;std::cin>>x;return x;}
USE1(T=int)vec<T>in(int n){vec<T>v;v.reserve(n);rep(i,n)v.pb(in<T>());return v;}
USE2(T,U=withi<T>)vec<U>zipi(const vec<T>&x,int s=0){int N=x.size();vec<U>v;v.reserve(N);rep(i,N)v.pb(x[i],s+i);return v;}
USE1(T)vec<T>ndvec(T v,int n){return vec<T>(n,v);}
USE2(T,...Ts)auto ndvec(T v,int n,Ts...ns)->vec<decltype(ndvec(v,ns...))>{return ndvec(ndvec(v,ns...),n);}
USE1(T)void pr(T x){std::cout<<x<<'\n';}
USE2(T,...Ts)void pr(T x,Ts...xs){std::cout<<x<<' ';pr(xs...);}
USE1(T=int)T rd(){T x=0,m=0,k;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||'9'<k)break;x=x*10+k-'0';}return x;}
USE1(T=int)void wr(T x,char c='\n'){int s=0,m=0;char b[32];if(x<0)m=1,x=-x;for(;x;x/=10)b[s++]=x%10;if(!s)b[s++]=0;if(m)mypc('-');for(;s--;)mypc(b[s]+'0');mypc(c);}
// clang-format on
// }}}
struct IoSetup { // {{{
  IoSetup() {
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.precision(10);
    std::cerr.precision(10);
  }
} iosetup; //}}}
using namespace std;
const int inf = 1001001001;
const ll infl = 1001001001001001001ll;
const int dd[] = {0, 1, 0, -1, 0};

signed main() {
  int N, M;
  while (N = in(), M = in()) {
    vector<int> infected(N + 1, 0);
    using Packet = std::pair<int, std::pair<int, int>>;
    vector<Packet> packet;
    rep(i, M) {
      int t = in(), s = in(), d = in();
      packet.push_back({t, {s, d}});
    }
    infected[1] = true;
    sort(ALL(packet));
    for (auto p : packet) {
      int s = p.se.fi;
      int d = p.se.se;
      infected[d] = infected[d] || infected[s];
    }
    pr(count(ALL(infected), 1));
  }
  return 0;
}