#include <bits/stdc++.h>
using namespace std;
struct candy {
  int t;
  int h, m;
  bool eat;
};
candy c[2005];
int n, x;
bool cmp(candy a, candy b) {
  if (a.m == b.m)
    return a.h > b.h;
  else
    return a.m > b.m;
}
int solve(int which) {
  for (int i = 0; i < n; i++) c[i].eat = false;
  int status = which, energy = x;
  int ans = 0;
  bool flag = false;
  for (int i = 0; i < n; i++) {
    if (c[i].t == which && c[i].h <= energy) {
      flag = true;
      c[i].eat = true;
      ans++;
      energy += c[i].m;
      break;
    }
  }
  if (!flag)
    return 0;
  else {
    flag = true;
    while (flag) {
      flag = false;
      for (int i = 0; i < n && !flag; i++) {
        if (!c[i].eat && c[i].t != status && c[i].h <= energy) {
          flag = true;
          c[i].eat = true;
          ans++;
          status = 1 - status;
          energy += c[i].m;
        }
      }
    }
    return ans;
  }
}
int main() {
  while (~scanf("%d%d", &n, &x)) {
    for (int i = 0; i < n; i++) {
      scanf("%d%d%d", &c[i].t, &c[i].h, &c[i].m);
      c[i].eat = false;
    }
    sort(c, c + n, cmp);
    int a1 = solve(0), a2 = solve(1);
    printf("%d\n", a1 > a2 ? a1 : a2);
  }
  return 0;
}
