// AOJ 2155: Infected Computer
// 2017.10.20 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct { int t, s, d; } T;
T tbl[20002];
char f[20002];

int cmp(T *a, T *b) { return a->t - b->t; }

char buf[102], *p;
int getInt(void)
{
	int n = 0;
	if (*p == ' ') p++;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}
int main()
{
	int n, m, i, ans;
	register T *t;

	while (fgets(p=buf, 100, stdin) && *p != '0') {
		n = getInt(), m = getInt();
		memset(f, 0, n+1);
		for (t = tbl, i = m; i--; t++) {
			fgets(p=buf, 100, stdin);
			t->t = getInt(), t->s = getInt(), t->d = getInt();
		}
		qsort(tbl, m, sizeof(T), cmp);
		for (f[1] = 1, t = tbl, i = m; i--; t++) f[t->d] |= f[t->s];
		for (ans = 0, i = 1; i <= n; i++) ans += f[i];
		printf("%d\n", ans);
	}
	return 0;
}