#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
struct node {
  int a, h, val;
} p[N];
int vis[N];
int main() {
  int n, x, a, b, c, ans = 0;
  ;
  scanf("%d%d", &n, &x);
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", &a, &b, &c);
    p[i] = (node){a, b, c};
  }
  for (int k = 0; k < 2; k++) {
    memset(vis, false, sizeof vis);
    int flag = 0;
    int cnt = 0;
    int sum = x;
    int curval = -1;
    int type = k;
    while (1) {
      curval = -1;
      for (int i = 0; i < n; i++) {
        if (!vis[i] && sum >= p[i].h && curval <= p[i].val && type == p[i].a) {
          curval = p[i].val;
          flag = i;
        }
      }
      if (curval == -1) break;
      vis[flag] = true;
      sum += curval;
      type ^= 1;
      cnt++;
    }
    ans = max(ans, cnt);
  }
  printf("%d\n", ans);
  return 0;
}
