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

#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[40], *p;
int getint(void)
{
	int n;
	n = 0; while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	p++;
	return n;
}

int main()
{
	int n, m, i, ans;
	T *t;
	char *q;

	while (fgets(p=buf, 20, stdin) && *p != '0') {
		n = getint(), m = getint();

		memset(f, 0, n+1);
		t = tbl, i = m; while (i--) {
			fgets(p=buf, 40, stdin);
			t->t = getint(), t->s = getint(), t->d = getint();
			t++;
		}
		qsort(tbl, m, sizeof(T), cmp);

		f[1] = 1, t = tbl, i = m; while (i--) f[t->d] |= f[t->s], t++;
		ans = 0, q = f+1, i = n; while (i--) ans += *q++;
		printf("%d\n", ans);
	}
	return 0;
}