#include<cstdio>
#include<algorithm>

#define	mp			make_pair
#define	rep(i,n)	for(int i=0;i<n;i++)

using namespace std;

typedef	pair<int,int>	pii;

int main(){
	for(int m,n;scanf("%d%d",&n,&m),n;){
		pair<int,pii> packet[20000];
		rep(i,m)	scanf("%d%d%d",&packet[i].first,&packet[i].second.first,&packet[i].second.second);
		sort(packet,packet+m);

		bool flg[20000]={};	flg[0]=true;
		rep(i,m){
			int src=packet[i].second.first-1,dst=packet[i].second.second-1;
			flg[dst]|=flg[src];
		}
		printf("%d\n",count(flg,flg+n,true));
	}

	return 0;
}