#include <bits/stdc++.h>
using namespace std;
int n;
int X, t[10000], h[10000], m[10000], v[10000];
int f(int x) {
  int ht = X;
  memset(v, 0, sizeof(v));
  for (int i = (0); i < (n); i++) {
    int tmp = -1;
    for (int j = (0); j < (n); j++) {
      if (v[j] || t[j] != ((i + x) & 1) || h[j] > ht) continue;
      if (tmp == -1) tmp = j;
      if (m[j] > m[tmp]) tmp = j;
    }
    if (tmp == -1) return i;
    ht += m[tmp];
    v[tmp] = 1;
  }
  return n;
}
int main() {
  scanf("%d%d", &n, &X);
  for (int i = (0); i < (n); i++) scanf("%d%d%d", t + i, h + i, m + i);
  int ans = 0, tmp = 0;
  ans = f(0);
  ans = max(ans, f(1));
  printf("%d\n", ans);
  return 0;
}
