#include <bits/stdc++.h>
typedef struct SWEET {
  int type;
  int height;
  int mass;
} sweet;
int cmp(const void *a, const void *b) {
  sweet *aa = (sweet *)a;
  sweet *bb = (sweet *)b;
  return (bb->mass - aa->mass);
}
int main() {
  sweet swe[2100];
  int vis[2100], n, x, i, t, ans1, j, ans2, p;
  while (~scanf("%d %d", &n, &x)) {
    for (i = 1; i <= n; i++) {
      scanf("%d%d%d", &swe[i].type, &swe[i].height, &swe[i].mass);
    }
    p = x;
    memset(vis, 0, sizeof(vis));
    qsort(&swe[1], n, sizeof(swe[1]), cmp);
    for (i = 1, t = 0, ans1 = 0; i <= n; i++) {
      for (j = 1; j <= n; j++) {
        if (t == swe[j].type || vis[j] == 1) {
          continue;
        }
        if (swe[j].height <= x) {
          x = x + swe[j].mass;
          vis[j] = 1;
          t = swe[j].type;
          ans1++;
          break;
        }
      }
    }
    memset(vis, 0, sizeof(vis));
    for (i = 1, t = 1, ans2 = 0; i <= n; i++) {
      for (j = 1; j <= n; j++) {
        if (t == swe[j].type || vis[j] == 1) {
          continue;
        }
        if (swe[j].height <= p) {
          p = p + swe[j].mass;
          vis[j] = 1;
          t = swe[j].type;
          ans2++;
          break;
        }
      }
    }
    if (ans1 > ans2)
      printf("%d\n", ans1);
    else
      printf("%d\n", ans2);
  }
  return 0;
}
