#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> N >> M;
	while (N) {
		vector<bool>flag(N + 1, false);
		flag[1] = true;
		vector<pair<int, pair<int, int>>>edge(M);
		for (int i = 0; i < M; i++) {
			cin >> edge[i].first >> edge[i].second.first >> edge[i].second.second;
		}
		sort(edge.begin(), edge.end());
		for (auto i : edge) {
			if (flag[i.second.first]) {
				flag[i.second.second] = true;
			}
		}
		int ans = 0;
		for (int i = 1; i <= N; i++) {
			if (flag[i]) {
				ans++;
			}
		}
		cout << ans << endl;
		cin >> N >> M;
	}
	return 0;
}