import sys input = sys.stdin.readline from heapq import heappop,heappush N,QU=map(int,input().split()) ANS=1 DIS=[1<<30]*(N+1) DIS[1]=0 E=[[] for i in range(N+1)] Q=[] for i in range(QU): p,x,y=map(int,input().split()) E[x].append((y,p)) if DIS[x]<=p: heappush(Q,(DIS[x],x)) while Q: now,town=heappop(Q) for to,time in E[town]: if now<=time: if DIS[to]==1<<30: ANS+=1 DIS[to]=time heappush(Q,(DIS[to],to)) elif DIS[to]>time: DIS[to]=time heappush(Q,(DIS[to],to)) print(ANS)