#include <bits/stdc++.h>
using namespace std;
struct candy {
  int t;
  int h;
  int m;
  bool used;
  candy() : t(0), h(0), m(0), used(false) {}
  candy(int t, int h, int m) : t(t), h(h), m(m), used(false) {}
};
int main() {
  int n, x;
  cin >> n >> x;
  vector<candy> c(n);
  for (int i = 0; i < n; i++) {
    int t, h, m;
    cin >> t >> h >> m;
    c[i] = candy(t, h, m);
  }
  int st = 0;
  int ans1 = 0, ans2 = 0;
  int x1 = x;
  for (int i = 0; i < n; i++) {
    int max_m = -1;
    int m_i = -1;
    for (int i = 0; i < n; i++) {
      if (c[i].h <= x1 && c[i].m > max_m && c[i].t == st && !c[i].used) {
        max_m = c[i].m;
        m_i = i;
      }
    }
    if (max_m == -1) {
      break;
    } else {
      c[m_i].used = true;
      ans1++;
      x1 += c[m_i].m;
      st = !st;
    }
  }
  st = 1;
  x1 = x;
  for (int i = 0; i < n; i++) {
    c[i].used = false;
  }
  for (int i = 0; i < n; i++) {
    int max_m = -1;
    int m_i = -1;
    for (int i = 0; i < n; i++) {
      if (c[i].h <= x1 && c[i].m > max_m && c[i].t == st && !c[i].used) {
        max_m = c[i].m;
        m_i = i;
      }
    }
    if (max_m == -1) {
      break;
    } else {
      c[m_i].used = true;
      ans2++;
      x1 += c[m_i].m;
      st = !st;
    }
  }
  cout << max(ans1, ans2);
  return 0;
}
