#include <bits/stdc++.h>
using namespace std;
struct node {
  int t, h, m;
};
node p[2222];
int book[2222];
bool cmp(node a, node b) {
  if (a.h == b.h)
    return a.m > b.m;
  else
    return a.h < b.h;
}
int main() {
  int n, x;
  scanf("%d%d", &n, &x);
  int xx = x;
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", &p[i].t, &p[i].h, &p[i].m);
  }
  sort(p, p + n, cmp);
  int cnt1 = 0, flag = 0;
  while (1) {
    int index = 0, mx = 0, tt = 0;
    for (int i = 0; p[i].h <= x && i < n; i++) {
      if ((flag == -1 || p[i].t != flag) && book[i] == 0 && p[i].m > mx) {
        index = i;
        mx = p[i].m;
        tt = 1;
      }
    }
    if (tt == 0) {
      break;
    }
    book[index] = 1;
    cnt1++;
    x += p[index].m;
    flag = p[index].t;
  }
  int cnt2 = 0;
  flag = 1;
  memset(book, 0, sizeof(book));
  x = xx;
  while (1) {
    int index = 0, mx = 0, tt = 0;
    for (int i = 0; p[i].h <= x && i < n; i++) {
      if ((flag == -1 || p[i].t != flag) && book[i] == 0 && p[i].m > mx) {
        index = i;
        mx = p[i].m;
        tt = 1;
      }
    }
    if (tt == 0) {
      break;
    }
    book[index] = 1;
    cnt2++;
    x += p[index].m;
    flag = p[index].t;
  }
  printf("%d", max(cnt1, cnt2));
  return 0;
}
