#include <bits/stdc++.h>
using namespace std;
struct candy {
  int t, h, m;
  candy() {}
  candy(int t, int h, int m) : t(t), h(h), m(m) {}
  bool operator<(const candy &a) const { return this->m < a.m; }
} C[2100];
int N, X;
int run(int lt) {
  bool vis[2100] = {0};
  int res = 0, x = X;
  for (int i = 0; i < N; ++i) {
    for (int j = N - 1; j >= 0; --j) {
      if (!vis[j] && C[j].h <= x && C[j].t != lt) {
        x += C[j].m;
        lt = C[j].t;
        vis[j] = 1;
        ++res;
        break;
      }
    }
  }
  return res;
}
int main() {
  scanf("%d %d", &N, &X);
  for (int i = 0; i < N; i++) {
    int t, h, m;
    scanf("%d %d %d", &t, &h, &m);
    C[i] = candy(t, h, m);
  }
  sort(C, C + N);
  printf("%d\n", max(run(0), run(1)));
  return 0;
}
