#include <bits/stdc++.h>
using namespace std;
struct bg {
  int h, mass, type;
};
const int nm = 2002;
int n, x;
bg a[nm];
bool fr[nm];
int main() {
  scanf("%d%d", &n, &x);
  int i, turn, kq, kq2, h, j;
  for (i = 1; i <= n; ++i) scanf("%d%d%d", &a[i].type, &a[i].h, &a[i].mass);
  turn = 0;
  kq = 0;
  h = x;
  memset(fr, 1, sizeof(fr));
  do {
    j = -1;
    for (i = 1; i <= n; ++i)
      if (fr[i] && turn == a[i].type && a[i].h <= h &&
          (j == -1 || a[i].mass > a[j].mass))
        j = i;
    if (j == -1) break;
    kq++;
    h += a[j].mass;
    fr[j] = 0;
    turn = 1 - turn;
  } while (1);
  turn = 1;
  kq2 = 0;
  h = x;
  memset(fr, 1, sizeof(fr));
  do {
    j = -1;
    for (i = 1; i <= n; ++i)
      if (fr[i] && turn == a[i].type && a[i].h <= h &&
          (j == -1 || a[i].mass > a[j].mass))
        j = i;
    if (j == -1) break;
    kq2++;
    h += a[j].mass;
    fr[j] = 0;
    turn = 1 - turn;
  } while (1);
  printf("%d", max(kq, kq2));
}
