#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
using triple=pair<int,pair<int,int> >;
#define tm first
#define src second.first
#define dst second.second
const int MAX_N=20010;
int n,m;
triple tp[MAX_N];
bool infected[MAX_N];

int main(){ _;
  while(cin>>n>>m,(n|m)!=0){
    REP(i,m){
      cin>>tp[i].tm>>tp[i].src>>tp[i].dst;
      tp[i].src--;
      tp[i].dst--;
    }
    sort(tp,tp+m);
    REP(i,n)infected[i]=false;
    infected[0]=true;
    REP(i,m)infected[tp[i].dst]|=infected[tp[i].src];
    int cnt=0;
    REP(i,n){
      if(infected[i])cnt++;
    }
    cout<<cnt<<endl;
  }
}