#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 5, INF = (int)1e9;
const long double EPS = 1e-9;
int t[N], h[N], m[N];
bool used[N];
int main() {
  int n, cur, ans = 0, ans1 = 0, tp, v = -1, first;
  cin >> n >> first;
  cur = first;
  for (int i = 0; i < n; i++) cin >> t[i] >> h[i] >> m[i];
  for (int i = 0; i < n; i++)
    if (t[i] == 0 && h[i] <= cur && (v == -1 || m[i] > m[v])) v = i;
  tp = 0;
  if (v != -1) {
    used[v] = 1;
    cur += m[v];
    ans++;
  }
  for (int i = 0; i < n; i++) {
    v = -1;
    for (int j = 0; j < n; j++)
      if (!used[j] && t[j] != tp && h[j] <= cur && (v == -1 || m[j] > m[v]))
        v = j;
    if (v == -1)
      break;
    else {
      tp = 1 - tp;
      used[v] = 1;
      cur += m[v];
      ans++;
    }
  }
  tp = 1;
  v = -1;
  cur = first;
  for (int i = 0; i < n; i++) used[i] = 0;
  for (int i = 0; i < n; i++)
    if (t[i] == 1 && h[i] <= cur && (v == -1 || m[i] > m[v])) v = i;
  if (v != -1) {
    used[v] = 1;
    cur += m[v];
    ans1++;
  }
  for (int i = 0; i < n; i++) {
    v = -1;
    for (int j = 0; j < n; j++)
      if (!used[j] && t[j] != tp && h[j] <= cur && (v == -1 || m[j] > m[v]))
        v = j;
    if (v == -1)
      break;
    else {
      tp = 1 - tp;
      used[v] = 1;
      cur += m[v];
      ans1++;
    }
  }
  cout << max(ans, ans1) << endl;
  return 0;
}
