#include <bits/stdc++.h>
using namespace std;
void Max(int &x, int y) { x = max(x, y); }
void Min(int &x, int y) { x = min(x, y); }
const int N = 2005;
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &a) {
  return os << '(' << a.first << ", " << a.second << ')';
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &a) {
  os << '[';
  for (unsigned int i = 0; i < a.size(); i++)
    os << a[i] << (i < a.size() - 1 ? ", " : "");
  os << ']';
  return os;
}
struct Candy {
  int t, h, m;
  Candy(int _t, int _h, int _m) : t(_t), h(_h), m(_m){};
  Candy(){};
};
int n;
Candy candy[N];
bool eat[N];
int findEat(int curH, int type) {
  pair<int, int> what = make_pair(-1, -1);
  for (signed i = (1); i <= (n); i++) {
    if (eat[i] || candy[i].t != type || candy[i].h > curH) continue;
    what = max(what, make_pair(candy[i].m, i));
  }
  if (what.first == -1) return 0;
  eat[what.second] = true;
  return 1 + findEat(curH + candy[what.second].m, type ^ 1);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int h;
  cin >> n >> h;
  for (signed i = (1); i <= (n); i++) {
    cin >> candy[i].t >> candy[i].h >> candy[i].m;
  }
  memset(eat, 0, sizeof(eat));
  int ans = findEat(h, 0);
  memset(eat, 0, sizeof(eat));
  ans = max(ans, findEat(h, 1));
  cout << ans << '\n';
}
