#include <bits/stdc++.h>
using namespace std;
struct candy {
  bool e;
  int t;
  int h;
  int m;
};
int main() {
  long long n, startHeight, total = 0, total2 = 0, jump, last = 0;
  cin >> n >> startHeight;
  jump = startHeight;
  candy aval[n], bval[n];
  for (int i = 0; i < n; i++) {
    cin >> aval[i].t >> aval[i].h >> aval[i].m;
    aval[i].e = false;
    bval[i] = aval[i];
  }
  for (int i = 0; i < n; i++) {
    long long temp = -1;
    long long max = 0;
    for (int j = 0; j < n; j++) {
      if (aval[j].h <= jump && aval[j].e == false && last != aval[j].t &&
          aval[j].m > max) {
        max = aval[j].m;
        temp = j;
      }
    }
    if (max > 0) {
      aval[temp].e = true;
      jump += aval[temp].m;
      total++;
      last = aval[temp].t;
    }
  }
  last = 1;
  jump = startHeight;
  for (int i = 0; i < n; i++) {
    long long temp = -1;
    long long max = 0;
    for (int j = 0; j < n; j++) {
      if (bval[j].h <= jump && bval[j].e == false && last != bval[j].t &&
          bval[j].m > max) {
        max = bval[j].m;
        temp = j;
      }
    }
    if (max > 0) {
      bval[temp].e = true;
      jump += bval[temp].m;
      total2++;
      last = bval[temp].t;
    }
  }
  cout << max(total, total2);
  return 0;
}
