#include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int N, M;
    cin >> N >> M;
    if (N == 0 && M == 0){
      break;
    }
    vector<tuple<int, int, int>> T(M);
    for (int i = 0; i < M; i++){
      int t, s, d;
      cin >> t >> s >> d;
      s--;
      d--;
      T[i] = make_tuple(t, s, d);
    }
    sort(T.begin(), T.end());
    vector<bool> I(N, false);
    I[0] = true;
    for (int i = 0; i < M; i++){
      int s = get<1>(T[i]);
      int d = get<2>(T[i]);
      if (I[s]){
        I[d] = true;
      }
    }
    int ans = 0;
    for (int i = 0; i < N; i++){
      if (I[i]){
        ans++;
      }
    }
    cout << ans << endl;
  }
}
