#include <bits/stdc++.h>
using namespace std;
template <class T1>
void deb(T1 e) {
  cout << e << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << endl;
}
vector<pair<int, int> > a, b;
bool colA[2005], colB[2005];
int main(void) {
  a.clear();
  b.clear();
  int n, x;
  scanf("%d %d", &n, &x);
  for (int i = 0; i < n; i++) {
    int tag, c, d;
    scanf("%d %d %d", &tag, &c, &d);
    if (tag)
      a.push_back(make_pair(c, d));
    else
      b.push_back(make_pair(c, d));
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  int tag = 0;
  int res = 0;
  int id1 = 0, id2 = 0;
  int curHeight = x;
  memset(colA, 0, sizeof(colA));
  memset(colB, 0, sizeof(colB));
  while (true) {
    if (tag) {
      int g = -1;
      int mx = -1;
      for (int i = 0; i < (int)a.size(); i++) {
        if (colA[i]) continue;
        if (a[i].first <= curHeight) {
          if (a[i].second > mx) {
            mx = a[i].second;
            g = i;
          }
        }
      }
      if (g == -1) break;
      res++;
      curHeight += a[g].second;
      colA[g] = true;
      tag = !tag;
    } else {
      int g = -1;
      int mx = -1;
      for (int i = 0; i < (int)b.size(); i++) {
        if (colB[i]) continue;
        if (b[i].first <= curHeight) {
          if (b[i].second > mx) {
            mx = b[i].second;
            g = i;
          }
        }
      }
      if (g == -1) break;
      res++;
      curHeight += b[g].second;
      colB[g] = true;
      tag = !tag;
    }
  }
  tag = 1;
  int nextRes = 0;
  id1 = 0, id2 = 0;
  curHeight = x;
  memset(colA, 0, sizeof(colA));
  memset(colB, 0, sizeof(colB));
  while (true) {
    if (tag) {
      int g = -1;
      int mx = -1;
      for (int i = 0; i < (int)a.size(); i++) {
        if (colA[i]) continue;
        if (a[i].first <= curHeight) {
          if (a[i].second > mx) {
            mx = a[i].second;
            g = i;
          }
        }
      }
      if (g == -1) break;
      nextRes++;
      curHeight += a[g].second;
      colA[g] = true;
      tag = !tag;
    } else {
      int g = -1;
      int mx = -1;
      for (int i = 0; i < (int)b.size(); i++) {
        if (colB[i]) continue;
        if (b[i].first <= curHeight) {
          if (b[i].second > mx) {
            mx = b[i].second;
            g = i;
          }
        }
      }
      if (g == -1) break;
      nextRes++;
      curHeight += b[g].second;
      colB[g] = true;
      tag = !tag;
    }
  }
  res = max(res, nextRes);
  deb(res);
  return 0;
}
