#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() {

  for(;;) {
    std::cin >> N >> M;
    if( N == 0 and M == 0 ) break;
    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) {
      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;
}
  