#include <bits/stdc++.h>
using namespace std;
template <class T>
void relax(T &a, T b) {
  a = min(a, b);
}
template <class T>
void mrelax(T &a, T b) {
  a = max(a, b);
}
struct candy {
  int t, h, m;
  bool f;
  void read() { scanf("%d %d %d", &t, &h, &m); }
};
candy cnd[2010];
int n, x;
int main() {
  scanf("%d %d", &n, &x);
  for (int i = 0; i < (int)n; i++) cnd[i].read();
  int r_max = 0;
  for (int _t = 0; _t < (int)2; _t++) {
    int r = 0, y = x, t = _t;
    for (int i = 0; i < (int)n; i++) cnd[i].f = true;
    while (1) {
      int curr = 0, m = -1;
      for (int i = 0; i < (int)n; i++)
        if (cnd[i].f && cnd[i].h <= y && cnd[i].m > curr && cnd[i].t == t)
          curr = cnd[i].m, m = i;
      if (m == -1) break;
      cnd[m].f = false, y += curr, t ^= 1, r++;
    }
    mrelax(r_max, r);
  }
  printf("%d\n", r_max);
  return 0;
}
