#include<iostream>
using namespace std;
typedef struct
{
	long t;
	int s, d;
}Data;
int main()
{
	int N, M;
	while (cin >> N >> M && N != 0 || M != 0)
	{
		Data data[20000];
		for (int i = 0; i < M; i++)
		{
			cin >> data[i].t >> data[i].s >> data[i].d;
			data[i].s--;
			data[i].d--;
		}

		for (int i = 0; i < M - 1; i++)
		{
			for (int j = i + 1; j < M; j++)
			{
				if (data[i].t > data[j].t)
				{
					Data tmp = data[i];
					data[i] = data[j];
					data[j] = tmp;
				}
			}
		}

		bool infected[20000];
		for (int i = 0; i < N; i++)infected[i] = false;
		infected[0] = true;
		for (int i = 0; i < M; i++)
		{
			if (infected[data[i].s])
			{
				infected[data[i].d] = true;
			}
		}

		int ans = 0;
		for (int i = 0; i < N; i++)
		{
			if (infected[i])ans++;
		}
		cout << ans << endl;
	}
	return 0;
}