#include <bits/stdc++.h>
using namespace std;
int t[3000];
int h[3000];
int m[3000];
int used[3000];
int main() {
  std::ios::sync_with_stdio(false);
  int n, x;
  cin >> n >> x;
  for (int i = 0; i < n; ++i) cin >> t[i] >> h[i] >> m[i];
  int res = 0;
  int cur = 0;
  int cur_x = x;
  while (true) {
    int cur_best = 0;
    int best_pos = -1;
    for (int i = 0; i < n; ++i) {
      if (used[i] || h[i] > cur_x) continue;
      if (t[i] != cur && (cur_best == 0 || m[i] > cur_best)) {
        cur_best = m[i];
        best_pos = i;
      }
    }
    if (best_pos == -1) break;
    cur = 1 - cur;
    ++res;
    cur_x += cur_best;
    used[best_pos] = 1;
  }
  memset(used, 0, sizeof(used));
  int res2 = 0;
  cur = 1;
  cur_x = x;
  while (true) {
    int cur_best = 0;
    int best_pos = -1;
    for (int i = 0; i < n; ++i) {
      if (used[i] || h[i] > cur_x) continue;
      if (t[i] != cur && (cur_best == 0 || m[i] > cur_best)) {
        cur_best = m[i];
        best_pos = i;
      }
    }
    if (best_pos == -1) break;
    cur = 1 - cur;
    ++res2;
    cur_x += cur_best;
    used[best_pos] = 1;
  }
  cout << std::max(res, res2) << endl;
  return 0;
}
