/* 
   AOJ 2155
   Infected Computer
*/

#include<stdio.h>
#define PACKETS_MAX 20001
#define COMPUTERS_MAX 20001
struct log
{
  int source, dest;
};


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

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

  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", &time);
	  scanf("%d %d", &log_set[time].source, &log_set[time].dest);
	}
      
      for(i = 1; i <= packetes_num; i++)
	{
	  if(computers[log_set[i].source])
	    {
	      computers[log_set[i].dest] = 1;
	      infected_computers_num++;
	    }
	}
      printf("%d\n", infected_computers_num);
      infected_computers_num = 1;
    }
  return 0;
}