#include <bits/stdc++.h>
using namespace std;
void fastio() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void one();
int main() {
  fastio();
  int t = 1;
  for (int i = 0; i < t; ++i) {
    one();
  }
  return 0;
}
void one() {
  int n;
  cin >> n;
  int x;
  cin >> x;
  vector<int> t(n), h(n), m(n);
  for (int i = 0; i < n; ++i) {
    cin >> t[i] >> h[i] >> m[i];
  }
  int ans = 0;
  for (int jstart = 0; jstart < 2; ++jstart) {
    int xx = x;
    vector<bool> was(n);
    int cnt = 0;
    int cur[2] = {0, 0};
    for (int i = 0; i < n; ++i) {
      int type = (jstart + i) % 2;
      int k = -1;
      for (int j = 0; j < n; ++j) {
        if (!was[j] && h[j] <= xx && t[j] == type) {
          if (k < 0 || m[k] < m[j]) {
            k = j;
          }
        }
      }
      if (k >= 0) {
        cnt++;
        xx += m[k];
        was[k] = true;
      } else {
        break;
      }
    }
    ans = max(ans, cnt);
  }
  cout << ans << endl;
}
