#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int, int> > le, ri;
int main() {
  int x;
  cin >> n >> x;
  for (int i = 0; i < n; ++i) {
    int t, h, m;
    scanf("%d %d %d", &t, &h, &m);
    if (t == 0)
      le.push_back(pair<int, int>(h, m));
    else
      ri.push_back(pair<int, int>(h, m));
  }
  bool leused[le.size()];
  bool riused[ri.size()];
  int res = 0;
  for (int turno = 0; turno < 2; ++turno) {
    memset(leused, 0, sizeof leused);
    memset(riused, 0, sizeof riused);
    int c = turno, fuerza = x;
    int parcial = 0;
    while (1) {
      bool valid = 0;
      if (c & 1) {
        int where = -1;
        for (int i = 0; i < le.size(); ++i)
          if (!leused[i] && fuerza >= le[i].first) {
            if (where == -1 || le[i].second > le[where].second) where = i;
          }
        if (where != -1) {
          valid = 1;
          leused[where] = 1;
          fuerza += le[where].second;
        }
      } else {
        int where = -1;
        for (int i = 0; i < ri.size(); ++i)
          if (!riused[i] && fuerza >= ri[i].first) {
            if (where == -1 || ri[i].second > ri[where].second) where = i;
          }
        if (where != -1) {
          valid = 1;
          riused[where] = 1;
          fuerza += ri[where].second;
        }
      }
      if (!valid) break;
      parcial++;
      c++;
    }
    res = max(res, parcial);
  }
  cout << res << endl;
  return 0;
}
