#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int N, M, t, s, d, ans;
  vector< vector<int> > packets;
  while (cin >> N >> M, N) {
    vector<bool> infected(N, false);
    infected[0] = true;
    for (int i = 0; i < M; ++i) {
      cin >> t >> s >> d;
      packets.push_back({t, s-1, d-1});
    }
    sort(packets.begin(), packets.end());
    for (int i = 0; i < M; ++i) {
      s = packets[i][1];
      d = packets[i][2];
      if (infected[s]) infected[d] = true;
    }
    ans = 0;
    for (int i = 0; i < N; ++i) if (infected[i]) ++ans;
    cout << ans << endl;
    packets.erase(packets.begin(), packets.end());
  }
  return 0;
}