#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
long long n, x, p = 0, q = 0;
pair<long long, long long> a[N], b[N];
long long solve() {
  long long cur = x;
  long long i = 1, j = 1, ans = 0;
  priority_queue<long long, vector<long long> > pq, pq2;
  while (true) {
    while (i <= p && a[i].first <= cur) {
      pq.push(a[i].second);
      i++;
    }
    if (pq.empty()) return ans;
    ans++;
    cur += pq.top();
    pq.pop();
    while (j <= q && b[j].first <= cur) {
      pq2.push(b[j].second);
      j++;
    }
    if (pq2.empty()) return ans;
    ans++;
    cur += pq2.top();
    pq2.pop();
  }
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> x;
  for (long long i = 1; i <= n; i++) {
    long long type;
    cin >> type;
    if (!type) {
      ++p;
      cin >> a[p].first >> a[p].second;
    } else {
      ++q;
      cin >> b[q].first >> b[q].second;
    }
  }
  sort(a + 1, a + p + 1);
  sort(b + 1, b + q + 1);
  long long ans = solve();
  swap(a, b);
  swap(p, q);
  long long ans2 = solve();
  cout << max(ans, ans2);
}
