#include <bits/stdc++.h>
using namespace std;
int rt[100000];
struct qq {
  int t;
  int h;
  int m;
} a[1000000];
bool o(qq x, qq y) {
  if (x.h < y.h || (x.h == y.h && x.m > y.m))
    return true;
  else
    return false;
}
int main() {
  int n, x;
  cin >> n >> x;
  int xx = x;
  for (int i = 0; i < n; i++) {
    cin >> a[i].t >> a[i].h >> a[i].m;
  }
  sort(a, a + n, o);
  int qq = 0;
  long long kol1 = 0;
  long long kol2 = 0;
  int i = 0;
  while (true) {
    int tt = -1;
    int tr = 0;
    bool ok = false;
    int maxx = -10000000;
    for (int j = 0; j < n; j++) {
      if (a[j].t == qq && a[j].h <= x && a[j].m > maxx && rt[j] == 0) {
        maxx = a[j].m;
        tt = j;
      }
    }
    if (tt == -1) break;
    rt[tt] = 1;
    x += a[tt].m;
    kol1++;
    qq = (qq + 1) % 2;
    i = tt;
  }
  for (int i = 0; i < n; i++) rt[i] = 0;
  qq = 1;
  x = xx;
  i = 0;
  while (true) {
    int tt = -1;
    int tr = 0;
    bool ok = false;
    int maxx = -10000000;
    for (int j = 0; j < n; j++) {
      if (a[j].t == qq && a[j].h <= x && a[j].m > maxx && rt[j] == 0) {
        maxx = a[j].m;
        tt = j;
      }
    }
    if (tt == -1) break;
    rt[tt] = 1;
    x += a[tt].m;
    kol2++;
    qq = (qq + 1) % 2;
    i = tt;
  }
  cout << max(kol1, kol2) << endl;
}
