#Created on 2015/03/15 ans import bisect [N, B] = map(int, input().split()) X = [] Y = [] P = [] for _ in range(N) : [x, y, p] = map(int, input().split()) X.append(x) Y.append(y) P.append(p) xs = sorted(list(set(X))) ys = sorted(list(set(Y))) points = [[0]*len(xs) for _ in range(len(ys))] counts = [[0]*len(xs) for _ in range(len(ys))] for i in range(N) : x = bisect.bisect_left(xs, X[i]) y = bisect.bisect_left(ys, Y[i]) points[y][x] += P[i] counts[y][x] += 1 for i in range(len(ys)) : for j in range(len(xs)) : if i > 0 : points[i][j] += points[i-1][j] counts[i][j] += counts[i-1][j] if j > 0 : points[i][j] += points[i][j-1] counts[i][j] += counts[i][j-1] if i > 0 and j > 0 : points[i][j] -= points[i-1][j-1] counts[i][j] -= counts[i-1][j-1] def get_sum(L, a, b, c, d) : ret = 0 ret += L[c][d] if a > 0 : ret -= L[a-1][d] if b > 0 : ret -= L[c][b-1] if a > 0 and b > 0 : ret += L[a-1][b-1] return ret ans = 0 #(i,j) (k, l) for i in range(len(ys)) : for j in range(len(xs)) : for k in range(i, len(ys)) : for l in range(j, len(xs)) : if get_sum(points,i,j,k,l) <= B : ans = max(ans, get_sum(counts,i,j,k,l)) print(ans)