#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 100000000;
int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; }
int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; }
long long fastMin(long long x, long long y) {
  return (((y - x) >> (64 - 1)) & (x ^ y)) ^ x;
}
long long fastMax(long long x, long long y) {
  return (((y - x) >> (64 - 1)) & (x ^ y)) ^ y;
}
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
int solve(vector<pair<int, int> > a[2], int x) {
  int t = 0;
  bool used[2][2000] = {};
  int ans = 0;
  int hi = x;
  while (true) {
    int selected = -1;
    pair<int, int> selected_p(-1, -1);
    for (int i = 0; i < (((int)(a[t]).size())); i++) {
      if (used[t][i]) continue;
      if (hi >= a[t][i].first) {
        if (a[t][i].second > selected_p.second) {
          selected = i;
          selected_p = a[t][i];
        }
      }
    }
    if (selected == -1) return ans;
    hi += selected_p.second;
    used[t][selected] = true;
    t ^= 1;
    ans++;
  }
}
int main() {
  int n, x;
  cin >> n >> x;
  vector<pair<int, int> > a[2];
  for (int i = 0; i < (n); i++) {
    int t, h, m;
    cin >> t >> h >> m;
    a[t].emplace_back(h, m);
  }
  for (int i = 0; i < (2); i++)
    sort(a[i].begin(), a[i].end(),
         [](const pair<int, int>& l, const pair<int, int>& r) {
           return l.first < r.first;
         });
  int ans = 0;
  for (int i = 0; i < (2); i++) {
    int tmp = solve(a, x);
    ans = max(ans, tmp);
    swap(a[0], a[1]);
  }
  cout << ans << endl;
}
