#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, a, b) for(int i=(a);i<(b);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 compx(int i, int j) {
return ps[i].x < ps[j].x;
}
bool compy(int i, int j) {
return ps[i].y < ps[j].y;
}
map > xm;
signed main()
{
cin >> N >> B;
ps.resize(N);
REP(i,N) cin >> ps[i].x >> ps[i].y >> ps[i].p;
vector xs;
vector ys;
REP(i,N) xs.push_back(i);
REP(i,N) ys.push_back(i);
sort(ALL(ys), compy);
sort(ALL(xs), compx);
int maxn = 0;
REP(i,N) REP(j,i+1) {
if (j && ps[xs[j-1]].x == ps[xs[j]].x) continue;
if (i < N-1 && ps[xs[i+1]].x == ps[xs[i]].x) continue;
int bottom = 0;
int top = 0;
int point = 0;
int num = 0;
vector qs;
FOR(k,j,i+1) {
qs.push_back(xs[k]);
}
sort(ALL(qs), compy);
// 尺取り法
while(top < qs.size()) {
P p = ps[qs[top]];
num++;
point += p.p;
while(top + 1 < qs.size() && ps[qs[top+1]].y == p.y) {
top++;
P p = ps[qs[top]];
point += p.p;
num++;
}
while (point > B) {
int y = ps[qs[bottom]].y;
while(bottom <= top && ps[qs[bottom]].y == y) {
point -= ps[qs[bottom]].p;
num--;
bottom++;
}
}
maxn = max(maxn, num);
// 次へ
top++;
}
}
cout << maxn << endl;
return 0;
}