import heapq from sortedcontainers import SortedSet n, q = map(int,input().split()) x = [-1] * q y = [-1] * q dp = [q+1] * n dp[0] = -1 horyu = [SortedSet() for i in range(n)] ans = 1 for num in range(q): p, x, y = map(int,input().split()) p -= 1 x -= 1 y -= 1 if dp[x] < p and dp[y] < p: pass elif dp[x] > p and dp[y] > p: horyu[x].add((p,y)) horyu[x].add((p,x)) else: if dp[y] < p: x, y = y, x assert dp[x] < p and dp[y] > p if dp[y] == q+1: ans += 1 dp[y] = p mada = [] heapq.heappush(mada, (-p, y)) while mada: t, i = heapq.heappop(mada) t = -t while True: itr = horyu[i].bisect_left((t, 0)) if itr == len(horyu[i]): break tim = horyu[i][itr][0] z = horyu[i][itr][1] horyu[i].discard(horyu[i][itr]) if dp[z] > tim: if dp[z] == q+1: ans += 1 dp[z] = tim heapq.heappush((-tim, z)) print(ans)