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

typedef pair<int, int> Data;
typedef pair<int, Data> Pair;

int n;
int m;
Pair ps[114514];
bool infected[114514];

int main() {
  while (1) {
    scanf("%d%d", &n, &m);
    if (n == 0 && m == 0) return 0; 

    fill(infected, infected+n+1, false);
    for (int i=0; i<m; i++) {
      int t, s, d;
      scanf("%d%d%d", &t, &s, &d);
      ps[i] = Pair(t, Data(s, d));
    }

    sort(ps, ps+m);

    infected[1] = true;
    int ans = 1;
    for (int i=0; i<m; i++) {
      Pair pa = ps[i];
      Data d = pa.second;
      int s = d.first;
      int t = d.second;

      if (infected[s] && !infected[t]) {
        infected[t] = true;
        ans++;
      }
    }

    printf("%d\n", ans);
  }
}