/* 
   AOJ 2155
   Infected Computer
*/

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

#define PACKETS_MAX 20001
#define COMPUTERS_MAX 20001
#define TIME_MAX 1000000000

struct log
{
  int time, source, dest;
};

struct log log_set[PACKETS_MAX];
int computers[COMPUTERS_MAX];

int comp(const void *a, const void *b)
{
  struct log *x = (struct log*)a;
  struct log *y = (struct log*)b;

  return x->time - y->time;
}

int main(void)
{
  int i, computers_num, packetes_num, infected_computers_num = 0;

  while(1)
    {
      scanf("%d %d", &computers_num, &packetes_num);
      if(computers_num == 0 && packetes_num == 0)
	{
	  break;
	}

      computers[1] = 1;
      for(i = 2; i <= computers_num; i++)
	{
	  computers[i] = 0;
	}

      for(i = 0; i < packetes_num; i++)
	{
	  scanf("%d %d %d", &log_set[i].time, &log_set[i].source, &log_set[i].dest);
	}

      qsort(log_set, packetes_num, sizeof(struct log), comp);
      
      for(i = 0; i < packetes_num; i++)
      	{
      	  if(computers[log_set[i].source])
      	    {
      	      computers[log_set[i].dest] = 1;
      	    }
      	}
      for(i = 1; i <= computers_num; i++)
	{
	  if(computers[i])
	    {
	      infected_computers_num++;
	    }
	}
      printf("%d\n", infected_computers_num);
      infected_computers_num = 0;
    }
  return 0;
}