import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines n, b=map(int, readline().split()) xyp=list(map(int, read().split())) xs=xyp[::3] ys=xyp[1::3] ps=xyp[2::3] qs=list(zip(xs, ys, ps)) qs.sort() ans=0 from bisect import bisect_left for i in range(n): if i>0 and qs[i-1][0]==qs[i][0]: continue z=[] for j in range(i, n): k=bisect_left(z, qs[j][1:]) z=z[:k]+[qs[j][1:]]+z[k:] if jb or (l>0 and z[l-1][0]==z[l][0])): s-=z[l][1] l+=1 if ans