#include <stdio.h>
#include <algorithm>
#include <tuple>
using namespace std;
int N, M; tuple<int, int, int> D[20000]; bool infected[20000];
int main() {
	while (true) {
		scanf("%d%d", &N, &M);
		if (N == 0 && M == 0) break;
		infected[0] = true;
		for (int i = 1; i < N; i++) infected[i] = false;
		for (int i = 0; i < M; i++) scanf("%d%d%d", &get<0>(D[i]), &get<1>(D[i]), &get<2>(D[i])), get<1>(D[i])--, get<2>(D[i])--;
		sort(D, D + M);
		int ret = 1;
		for (int i = 0; i < M; i++) {
			if (infected[get<1>(D[i])] && !infected[get<2>(D[i])]) {
				infected[get<2>(D[i])] = true; ret++;
			}
		}
		printf("%d\n", ret);
	}
	return 0;
}