#include <bits/stdc++.h>
void candyeating0(int x, int counter);
void candyeating1(int x, int counter);
using namespace std;
int possibility;
int counter1, counter0;
int used1[20000], used0[20000];
struct CANDY {
  int hi, mass;
};
CANDY candy1[20000], candy0[20000];
int findmax_mass0(int i) {
  int x = 0, maxn = 0, y = -1;
  while (x <= i) {
    if (used0[x] == 0 && candy0[x].mass >= maxn) {
      maxn = candy0[x].mass;
      y = x;
    }
    x++;
  }
  return y;
}
int findmax_mass1(int i) {
  int x = 0, maxn = 0, y = -1;
  while (x <= i) {
    if (used1[x] == 0 && candy1[x].mass >= maxn) {
      maxn = candy1[x].mass;
      y = x;
    }
    x++;
  }
  return y;
}
void candyeating0(int x, int counter) {
  int i = 0, v;
  while (i < counter0 && candy0[i].hi <= x) {
    i++;
  }
  v = findmax_mass0(i - 1);
  if (v == -1) {
    if (possibility <= counter) possibility = counter;
    return;
  }
  used0[v] = 1;
  candyeating1(x + candy0[v].mass, counter + 1);
  used0[v] = 0;
}
void candyeating1(int x, int counter) {
  int i = 0, v;
  while (i < counter1 && candy1[i].hi <= x) {
    i++;
  }
  v = findmax_mass1(i - 1);
  if (v == -1) {
    if (possibility <= counter) possibility = counter;
    return;
  }
  used1[v] = 1;
  candyeating0(x + candy1[v].mass, counter + 1);
  used1[v] = 0;
}
bool cmp(CANDY i, CANDY j) { return i.hi < j.hi; }
int main() {
  int n, a, b, c, y;
  while (scanf("%d %d", &n, &y) != EOF) {
    possibility = 0;
    counter1 = 0;
    counter0 = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d %d %d", &a, &b, &c);
      if (a == 1) {
        candy1[counter1].hi = b;
        candy1[counter1++].mass = c;
      } else {
        candy0[counter0].hi = b;
        candy0[counter0++].mass = c;
      }
    }
    sort(candy0, candy0 + counter0, cmp);
    sort(candy1, candy1 + counter1, cmp);
    memset(used0, 0, sizeof(used0));
    memset(used1, 0, sizeof(used1));
    candyeating0(y, 0);
    candyeating1(y, 0);
    printf("%d\n", possibility);
  }
}
