#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:66777216")
using namespace std;
int solve(int x, vector<pair<int, int> > A, vector<pair<int, int> > B) {
  int i = 0, j = 0;
  int na = (int)(A).size();
  int nb = (int)(B).size();
  vector<bool> a(na, false);
  vector<bool> b(nb, false);
  while (true) {
    if ((i + j) & 1) {
      if (j == nb) break;
      int pos = -1, maxi = -1;
      for (int u = 0; u < nb; ++u) {
        if (!b[u]) {
          if (B[u].second > maxi && B[u].first <= x) {
            maxi = B[u].second;
            pos = u;
          }
        }
      }
      if (pos == -1) break;
      b[pos] = true;
      x += maxi;
      ++j;
    } else {
      if (i == na) break;
      int pos = -1, maxi = -1;
      for (int u = 0; u < na; ++u) {
        if (!a[u]) {
          if (A[u].second > maxi && A[u].first <= x) {
            maxi = A[u].second;
            pos = u;
          }
        }
      }
      if (pos == -1) break;
      a[pos] = true;
      x += maxi;
      ++i;
    }
  }
  return i + j;
}
int main() {
  int n, x;
  cin >> n >> x;
  vector<pair<int, int> > A, B;
  for (int i = 0; i < n; ++i) {
    int ty;
    cin >> ty;
    int h, m;
    cin >> h >> m;
    if (ty == 0)
      A.push_back(make_pair(h, m));
    else
      B.push_back(make_pair(h, m));
  }
  sort((A).begin(), (A).end());
  sort((B).begin(), (B).end());
  int ans = max(solve(x, A, B), solve(x, B, A));
  cout << ans << endl;
  return 0;
}
