#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

typedef pair<int,int> P;
typedef pair<int,P> PP;
const int MAX = 20001;
bool infected[MAX];
int N,M;

void init(){
  fill(infected,infected+MAX,false);
  infected[1] = true;
}

int main(){
  
  while(cin >> N >> M && N+M){
    init();
    vector<PP> V;
    for(int i = 0; i < M; i++){
      PP pp;
      cin >> pp.first >> pp.second.first >> pp.second.second;
      V.push_back(pp);
    }
    sort(V.begin(),V.end());

    for(int i = 0; i < V.size(); i++){
      infected[V[i].second.second] = (infected[V[i].second.second]
				      ||infected[V[i].second.first]);
    }

    int ans = 0;
    for(int i = 1; i <= N; i++)
      if(infected[i]) ans++;
    cout << ans << endl;
  }
  return 0;
}