#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for(int i=0; i<(n); i++)
#define ALL(a) (a).begin(),(a).end()
struct P { int x, y, p; P(){}; P(int _x, int _y): x(_x), y(_y){}; };
int N,T,B;
vector
ps;
bool comp(int i, int j) {
return ps[i].y < ps[j].y;
}
signed main()
{
cin >> N >> B;
ps.resize(N);
REP(i,N) cin >> ps[i].x >> ps[i].y >> ps[i].p;
vector ys;
REP(i,N) ys.push_back(i);
sort(ALL(ys), comp);
int maxn = 0;
REP(i,N) REP(j,i) {
int x0 = min(ps[i].x, ps[j].x);
int x1 = max(ps[i].x, ps[j].x);
int bottom = 0;
int top = -1;
int point = 0;
int num = 0;
// 尺取り法
while(top < N) {
if (top == -1) {
P p = ps[ys[bottom]];
if (p.x < x0 || x1 < p.x) {
bottom++;
continue;
}
top = bottom;
}
P p = ps[ys[top]];
if (p.x < x0 || x1 < p.x) {
top++;
continue;
}
num++;
point += p.p;
while(top + 1 < N && ps[ys[top+1]].y == ps[ys[top]].y) {
top++;
P p = ps[ys[top]];
if (p.x < x0 || x1 < p.x) {
continue;
}
point += p.p;
num++;
}
while (point > B) {
point -= ps[ys[bottom]].p;
num--;
bottom++;
}
maxn = max(maxn, num);
// 次へ
top++;
}
}
cout << maxn << endl;
return 0;
}