/*
AizuOnline A2155
Title
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section
int N,M;
struct msg_st
{
        int t;  //time
        int s;  //src
        int d;  //dst
} msg[20000];
char infected[20001];
int inf_machine;
//
int compare_msg(const void *a, const void *b)
{
        return(((struct msg_st *)a)->t - ((struct msg_st *)b)->t);
}


main()
{
        int i;

        while(scanf("%d %d",&N,&M) && (N||M))
        {
                for(i=0;i<M;i++)
                        scanf("%d %d %d",&msg[i].t,&msg[i].s,&msg[i].d);
                memset(infected,0,N+1);
                infected[1]=-1;
                inf_machine=1; 
                qsort(msg,M,sizeof(struct msg_st),compare_msg);
                for(i=0;i<M;i++)
                {
                        if(infected[msg[i].s] && (!infected[msg[i].d]))
                        {
                                infected[msg[i].d]=-1;
                                inf_machine++;
                        }
                }
                printf("%d\n",inf_machine);
        }
return(0);
}