#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

struct A{
	int t,s,d;
	A(int t,int s,int d):t(t),s(s),d(d){}
	bool operator<(const A &a)const{return t<a.t;}
};

bool infected[20000];
int main(){
	int n,m;
	while(cin>>n>>m,n||m){
		vector<A> v;
		v.reserve(m);
		memset(infected,false,sizeof(infected));
		infected[0]=true;
		rep(i,m){
			int t,s,d;
			cin>>t>>s>>d;
			v.push_back(A(t,s-1,d-1));
		}
		sort(v.begin(),v.end());
		rep(i,v.size()){
			infected[v[i].d] |= infected[v[i].s];
		}
		cout<<count(infected,infected+n,true)<<endl;
	}
	return 0;
}