#include <iostream>
#include <queue>
#include <string.h>
using namespace std;
struct E{
	long long int t;
	int from,to;
	bool operator<(const E& e1)const{
		return t>e1.t;
	}
};
void f(int n,int m){
	int memo[20003];
	memset(memo,0,sizeof(memo));
	memo[1]=1;
	priority_queue<E> pq;
	for(int i=0;i<m;i++){
		E e1;
		cin>>e1.t>>e1.from>>e1.to;
		pq.push(e1);
	}
	while(pq.size()>0){
		E e1=pq.top();
		pq.pop();
		if(memo[e1.from]==1)memo[e1.to]=1;
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		ans+=memo[i];
	}
	cout<<ans<<endl;
}


int main() {
	int n,m;
	while(true){
		cin>>n>>m;
		if(n+m==0)break;
		f(n,m);
	}
	return 0;
}