#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;
}
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) {
        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 == ps[qs[top]].y) {
                top++;
                P p = ps[qs[top]];
                point += p.p;
                num++;
            }
            while (point > B) {
                point -= ps[qs[bottom]].p;
                num--;
                bottom++;
                while(bottom <= top && ps[qs[bottom-1]].y == ps[qs[bottom]].y) {
                    point -= ps[qs[bottom]].p;
                    num--;
                    bottom++;
                }
            }
            maxn = max(maxn, num);
            // 次へ
            top++;
        }
    }
    cout << maxn << endl;
    return 0;
}