#include <iostream>
#include <vector>
#include <algorithm>

using std::cin;
using std::cout;
using std::endl;

struct data_t {
	int time;
	int sent;
	int res;

	bool operator<(const data_t& right) const {
		return ( time == right.time ) || ( time < right.time );
	}
};

int main(void) {
	int N,M;
	cin >> N;
	cin >> M;

	while (N != 0 || M != 0) {
		std::vector<data_t> record(M);

		for (int i = 0; i < M; i++) {
			cin >> record[i].time;
			cin >> record[i].sent;
			cin >> record[i].res;
		}

		std::sort(record.begin(), record.end());

		std::vector<bool> infected(N, false);
		infected[0] = true;
		int count = 1;

		for (int i = 0; i < M; i++) {
			if (infected[record[i].sent-1]) {
				if (!(infected[record[i].res-1])) {
					infected[record[i].res-1] = true;
					count++;
				}
			}
		}
		cout << count << endl;
		cin >> N;
		cin >> M;
	}

	return 0;
}