#include "bits/stdc++.h"
using namespace std;

struct cust {
	int m;
	int l;
	int k;
};
 
struct query {
	int type;
	int time;
	int id;
};
class Compare {
public:
	bool operator()(const query&l,const query&r) {
		return l.time==r.time?l.type==r.type?l.id>r.id:l.type>r.type:l.time > r.time;
	}
};

bool check(const int T, const vector<cust>&cus, const int n) {
	int waitnum = n;
	priority_queue<query,vector<query>,Compare>que;
	set<int>waits;
	for (int i = 0; i < cus.size(); ++i) {
		que.push(query{ 0,0,i });
	}
	while (!que.empty()) {
		query q(que.top());
		que.pop();
		//call start
		 if (q.type == 0) {
			const int cid = q.id;
			if (waitnum) {
				waitnum--;
				const int nexttime = q.time + cus[cid].m;
				if (nexttime <= T) {
					que.push(query{ 1,nexttime,0 });
				}else {
					return false;
				}
			}
			else {
				waits.emplace(cid);
				const int nexttime = q.time + cus[cid].l;
				que.push(query{ 2,nexttime,cid });
			}
		//call end
		}else if (q.type == 1) {
			auto it = waits.begin();
			if (it == waits.end()) {
				waitnum++;
			}
			else {
				const int cid = *it;
				const int nexttime = q.time + cus[cid].m;
				if (nexttime <= T) {
					waits.erase(it);
					que.push(query{ 1,nexttime,0 });
				}
				else {
					return false;
				}
			}
		//give up call
		}else if (q.type == 2) {
			const int cid = q.id;
			auto it = waits.find(cid);
			if (it!=waits.end()) {
				waits.erase(it);
				const int nexttime = q.time + cus[cid].k;
				if (nexttime <= T-cus[cid].m) {
					que.push(query{ 0,nexttime,cid });
				}
				else {
					return false;
				}
			}
		}
	}
	return true;
}

int main() {
	while (1) {
		int N, T; cin >> N >> T;
		if (!N)break;
		vector<cust>cus;
		int totalm = 0;
		for (int i = 0; i < N; ++i) {
			int m, l, k; cin >> m >> l >> k;
			totalm += m;
			cus.push_back(cust{ m,l,k });
		}
		int amin = (totalm-1) / T + 1;
		for (int n = amin; n <= N; ++n) {
			if (check(T, cus, n)) {
				cout << n << endl;
				break;
			}
		}
	}
	
	return 0;
}