#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-15;
const long double PI = 3.14159265358979323846;
inline int lg2(long long n) {
  int h = 0;
  while ((1ll << h) < n) ++h;
  return h;
}
struct configio {
  configio() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
  }
} cnfio;
int diff(int a, int b, int mod) { return ((a - b) % mod + mod) % mod; }
struct candy {
  int h, m;
};
int main() {
  int n, x;
  cin >> n >> x;
  vector<candy> v1[2];
  for (int i = 0; i < n; ++i) {
    int t, h, m;
    cin >> t >> h >> m;
    v1[t].push_back({h, m});
  }
  long long ans = 0;
  for (int type = 0; type <= 1; ++type) {
    vector<candy> v[2];
    v[0] = v1[0];
    v[1] = v1[1];
    int cur_ans = 0;
    long long cur_x = x;
    int cur_type = type;
    while (true) {
      int id = -1;
      for (int i = 0; i < v[cur_type].size(); ++i) {
        if (v[cur_type][i].h <= cur_x) {
          if (id == -1 || (v[cur_type][id].m < v[cur_type][i].m)) {
            id = i;
          }
        }
      }
      if (id == -1) {
        break;
      }
      cur_ans++;
      cur_x += v[cur_type][id].m;
      v[cur_type].erase(v[cur_type].begin() + id);
      cur_type ^= 1;
    }
    ans = max(ans, (long long)cur_ans);
  }
  cout << ans << endl;
  return 0;
}
