#include <bits/stdc++.h>
using namespace std;
int n, x;
vector<pair<int, int> > a[2], b[2];
int ans;
void solve(int id) {
  int cnt = 0;
  int h = x;
  int i, k;
  while (1) {
    int mx = 0, k = -1;
    for (i = 0; i < b[id].size(); i++) {
      if (b[id][i].first <= h) {
        if (b[id][i].second > mx) {
          mx = b[id][i].second;
          k = i;
        }
      }
    }
    if (k == -1) break;
    cnt++;
    h += b[id][k].second;
    b[id].erase(b[id].begin() + k);
    id = !id;
  }
  ans = max(ans, cnt);
}
int main() {
  int i, t, h, m;
  cin >> n >> x;
  for (i = 0; i < n; i++) {
    scanf("%d%d%d", &t, &h, &m);
    a[t].push_back(make_pair(h, m));
  }
  ans = 0;
  b[0] = a[0], b[1] = a[1];
  solve(0);
  b[0] = a[0], b[1] = a[1];
  solve(1);
  cout << ans << endl;
}
