# coding: utf-8 N,B = map(int,raw_input().split()) xyp = [map(int,raw_input().split()) for i in xrange(N)] xy = list(set((x1,y2) for x1,y1,p1 in xyp for x2,y2,p2 in xyp)) M = len(xy) ans = 1 for i in xrange(M): x1,y1 = xy[i] for j in xrange(i+1,M): x2,y2 = xy[j] l,r,d,u = min(x1,x2),max(x1,x2),min(y1,y2),max(y1,y2) in_square = [p for x,y,p in xyp if r >= x >= l and u >= y >= d] if sum(in_square) <= B: ans = max(ans, len(in_square)) print ans