#include <iostream>
#include <algorithm>

using namespace std;

typedef long long int lli;

struct P{
	int t;
	int s;
	lli d;
};

bool comp(const P& a, const P& b)
{
	return a.t < b.t;
}

int main()
{
	int n, m, c;
	P a[20001];
	bool af[20001];
	
	while(cin>>n>>m && (n+m)){
		for(int i = 0; i < m; i++){
			cin >> a[i].t >> a[i].s >> a[i].d;
		}
		c = 0;
		fill(af, af+(n+1), false);
		sort(a, a+m, comp);
		af[1] = true;
		
		for(int i = 0; i < m; i++){
			af[a[i].d] = (af[a[i].s]|af[a[i].d]);
		}
		
		for(int i = 1; i <= n; i++){
			if(af[i]){
				c++;
			}
		}
		
		cout << c << endl;
	}

	return 0;
}