#include <bits/stdc++.h>
using namespace std;
int type[2007], h[2007], m[2007];
int vis[2007], n, X;
int work(int flag) {
  int i, j;
  memset(vis, 0, sizeof(vis));
  int tag;
  int x = X;
  int cnt = 0;
  while (1) {
    tag = -1;
    for (i = 0; i < n; i++) {
      if (!vis[i] && flag == type[i] && x >= h[i] &&
          (tag == -1 || m[i] > m[tag]))
        tag = i;
    }
    if (tag == -1) break;
    cnt++;
    vis[tag] = 1;
    x += m[tag];
    flag = 1 - flag;
  }
  return cnt;
}
int main() {
  int i, j;
  while (scanf("%d%d", &n, &X) != EOF) {
    for (i = 0; i < n; i++) scanf("%d%d%d", &type[i], &h[i], &m[i]);
    printf("%d\n", max(work(0), work(1)));
  }
  return 0;
}
