#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000;
multiset<pair<int, int> > a, b;
int n, h;
void read() {
  scanf("%d%d", &n, &h);
  for (int i = 1; i <= n; i++) {
    int t, u, v;
    scanf("%d%d%d", &t, &u, &v);
    if (t)
      a.insert(pair<int, int>(u, v));
    else
      b.insert(pair<int, int>(u, v));
  }
}
int choose(multiset<pair<int, int> > a, multiset<pair<int, int> > b) {
  int ans = 0, hei = h;
  bool t = 0;
  while (a.size() || b.size()) {
    if (t && b.size() == 0) return ans;
    if ((!t) && a.size() == 0) return ans;
    if (t == 0) {
      multiset<pair<int, int> >::iterator c = a.end();
      for (auto it = a.begin(); it != a.end(); it++) {
        if (it->first > hei) break;
        if (c == a.end() || it->second > c->second) c = it;
      }
      if (c == a.end()) return ans;
      ans++;
      hei += c->second;
      a.erase(c);
    } else {
      multiset<pair<int, int> >::iterator c = b.end();
      for (auto it = b.begin(); it != b.end(); it++) {
        if (it->first > hei) break;
        if (c == b.end() || it->second > c->second) c = it;
      }
      if (c == b.end()) return ans;
      ans++;
      hei += c->second;
      b.erase(c);
    }
    t = !t;
  }
  return ans;
}
void work() {
  int ans = max(choose(a, b), choose(b, a));
  printf("%d\n", ans);
}
int main() {
  read();
  work();
  return 0;
}
