#include <bits/stdc++.h>
using namespace std;
int cnt(bool f, vector<pair<int, int> > a[2], int cur) {
  int ans = 0, mx[2] = {0, 0}, dx = -1;
  vector<vector<bool> > b(2, vector<bool>(max(a[0].size(), a[1].size())));
  for (int i = 0; i < a[f].size(); i++) {
    if (a[f][i].first <= cur && a[f][i].second > mx[f])
      mx[f] = a[f][i].second, dx = i;
  }
  while (dx != -1) {
    ans++, cur += mx[f], mx[f] = 0, b[f][dx] = 1, dx = -1, f = !f;
    for (int i = 0; i < a[f].size(); i++) {
      if (!b[f][i] && a[f][i].first <= cur && a[f][i].second > mx[f])
        mx[f] = a[f][i].second, dx = i;
    }
  }
  return ans;
}
int main() {
  int n, cur, ans = 0;
  cin >> n >> cur;
  vector<pair<int, int> > a[2];
  for (int i = 0; i < n; i++) {
    int t, h, m;
    cin >> t >> h >> m;
    a[t].push_back(make_pair(h, m));
  }
  cout << max(cnt(0, a, cur), cnt(1, a, cur)) << endl;
}
