#include <bits/stdc++.h>
using namespace std;
int res(vector<vector<pair<int, int> > > a, int x) {
  int now = 0;
  int r = 0;
  vector<vector<bool> > t(2);
  t[0].resize(a[0].size());
  t[1].resize(a[1].size());
  while (true) {
    int best = -1;
    int v = 0;
    for (long long i = 0; i < a[now].size(); i++) {
      if (v < a[now][i].second && x >= a[now][i].first && !t[now][i]) {
        best = i;
        v = a[now][i].second;
      }
    }
    if (best == -1) return r;
    t[now][best] = true;
    x += a[now][best].second;
    r++;
    now = 1 - now;
  }
}
int main() {
  int n, x, ans;
  cin >> n >> x;
  vector<vector<pair<int, int> > > a, b;
  a.resize(2);
  b.resize(2);
  for (long long i = 0; i < n; i++) {
    int c, h, w;
    cin >> c >> h >> w;
    a[c].emplace_back(h, w);
    b[1 - c].emplace_back(h, w);
  }
  cout << max(res(a, x), res(b, x));
}
