#include <bits/stdc++.h>
using namespace std;

typedef pair<long long, long long> P;
typedef pair<long long, P> PP;

void solve(int n, int m){
	vector<PP> v;
	for(int i=0; i<m; ++i){
		int t, s, d;
		cin >> t >> s >> d;
		v.push_back(PP(t, P(s, d)));
	}
	sort(v.begin(), v.end());
	bool a[20010] = {};
	a[1] = true;
	for(int i=0; i<m; ++i)
		a[v[i].second.second] |= a[v[i].second.first];
	int res = 0;
	for(int i=1; i<=n; ++i)
		if(a[i])
			++res;
	cout << res << "\n";
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	while(1){
		int n, m;
		cin >> n >> m;
		if(n == 0 && m == 0) return 0;
		solve(n, m);
	}
}
