from collections import defaultdict from operator import itemgetter import sys from heapq import * sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def SI(): return sys.stdin.readline()[:-1] def main(): inf=10**9 n,m=MI() abx=defaultdict(list) bax=defaultdict(list) cnt2=cnt3=0 bb=set() for _ in range(n): x,a,b=MI() if x>=3:cnt3+=1 else: abx[a].append((b,x)) bax[b].append((a,x)) bb.add(b) if x==2:cnt3+=1 if x==1:cnt2+=1 bb=list(sorted(bb)) hp0=[] hp12=[] hp10=[] hp2=[] ans=cnt3 sb=inf for a,bx in sorted(abx.items()): sa=a for b,x in bx: if x==2 and bsa:heappush(hp0,a);cnt2+=1 if x==1 and a>sa:heappush(hp12,a);cnt2-=1;cnt3+=1 while hp2 and -hp2[0]>=sb:heappop(hp2);cnt3+=1;cnt2-=1 while hp10 and -hp10[0]>=sb:heappop(hp10);cnt2+=1 #print(cnt2,cnt3,hp0,hp10,hp12,hp2) if cnt2+cnt3