#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  cin >> n >> x;
  vector<int> t(n), h(n), m(n);
  for (int i = 0; i < n; i++) cin >> t[i] >> h[i] >> m[i];
  int count = 0;
  int height = x, type = 0;
  vector<bool> eaten(n);
  while (1) {
    int mass = 0, j = 0;
    bool flag = 0;
    for (int i = 0; i < n; i++) {
      if (!eaten[i]) {
        if (t[i] == type) {
          if (h[i] <= height) {
            flag = 1;
            if (m[i] > mass) {
              j = i;
              mass = m[i];
            }
          }
        }
      }
    }
    if (!flag) break;
    height += mass;
    type = !type;
    eaten[j] = 1;
    count++;
  }
  eaten.clear();
  eaten.resize(n);
  int count2 = 0;
  height = x, type = 1;
  while (1) {
    int mass = 0, j = 0;
    bool flag = 0;
    for (int i = 0; i < n; i++) {
      if (!eaten[i]) {
        if (t[i] == type) {
          if (h[i] <= height) {
            flag = 1;
            if (m[i] > mass) {
              j = i;
              mass = m[i];
            }
          }
        }
      }
    }
    if (!flag) break;
    height += mass;
    type = !type;
    eaten[j] = 1;
    count2++;
  }
  cout << max(count, count2) << endl;
}
