#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;
  while(cin>>n>>m,n+m){
    vector<pair<ll,pair<ll,ll>>>pll(m);
    for(int i=0;i<m;i++){
      ll t,f,to;
      cin>>t>>f>>to;
      pll[i]=(mp(t,mp(f-1,to-1)));
    }
    sort(ALL(pll));
    vector<bool> virus(n,false);
    virus[0] = true;
    for(int i=0;i<m;i++){
      ll f = pll[i].S.F;
      ll t = pll[i].S.S;
      if(virus[f])virus[t] = true;
    }
    ll ans=0;
    for(auto a:virus)ans+=a;
    cout<<ans<<endl;
  }
  return 0;
}

