#include <bits/stdc++.h>
using namespace std;
const long long M = 1000000007;
const long long MM = 998244353;
long long begtime = clock();
long long newmod(long long a, long long b) { return ((a % b) + b) % b; }
long long powM(long long a, long long b, long long m) {
  if (a <= 0) return 0;
  a %= m;
  if (!b) return 1;
  long long ans = 1LL;
  while (b) {
    if (b & 1) ans = ans * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return ans;
}
long long poww(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a;
    a = a * a;
    b >>= 1;
  }
  return ans;
}
template <typename T, typename F>
void chmax(T &a, F b) {
  if (b > a) a = b;
}
template <typename T, typename F>
void chmin(T &a, F b) {
  if (b < a) a = b;
}
const long long N = 1e6 + 1;
long long solve(long long type, vector<pair<long, long> > t1,
                vector<pair<long, long> > t0, long long x) {
  long long ans = 0;
  long long flag = 0;
  while (!flag) {
    long long pos = -1, mx = 0;
    if (!type) {
      type = 1;
      for (int i = 0; i < ((long long)t0.size()); i++) {
        if (t0[i].first <= x && t0[i].second > mx) {
          pos = i;
          mx = max(mx, (long long)t0[i].second);
        }
      }
      if (pos == -1) {
        flag = 1;
        break;
      }
      ans++;
      x += mx;
      t0.erase(t0.begin() + pos);
    } else {
      type = 0;
      long long pos = -1, mx = 0;
      for (int i = 0; i < ((long long)t1.size()); i++) {
        if (t1[i].first <= x && t1[i].second > mx) {
          mx = max(mx, (long long)t1[i].second);
          pos = i;
        }
      }
      if (pos == -1) {
        flag = 1;
        break;
      }
      ans++;
      x += mx;
      t1.erase(t1.begin() + pos);
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long n, x;
  cin >> n >> x;
  vector<pair<long, long> > t0, t1;
  for (long long i = 0; i < n; i++) {
    long long t;
    cin >> t;
    long long a, b;
    cin >> a >> b;
    if (t) {
      t1.push_back({a, b});
    } else {
      t0.push_back({a, b});
    }
  }
  cout << max(solve(1, t1, t0, x), solve(0, t1, t0, x));
  return 0;
}
