#include <bits/stdc++.h>
using namespace std;
struct can {
  int h, m;
};
vector<can> v[2];
int n, x;
bool vis[2][2000];
int calc(bool f) {
  memset(vis, 0, sizeof(vis));
  int cur = x;
  int res = 0;
  while (true) {
    int mx = 0, idx = -1;
    for (int i = 0; i < v[f].size(); ++i)
      if (!vis[f][i] && cur >= v[f][i].h && mx < v[f][i].m) {
        mx = v[f][i].m;
        idx = i;
      }
    if (idx == -1) break;
    cur += mx;
    vis[f][idx] = true;
    f = !f;
    ++res;
  }
  return res;
}
int main() {
  cin >> n >> x;
  int t;
  can z;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &t);
    scanf("%d%d", &z.h, &z.m);
    v[t].push_back(z);
  }
  printf("%d\n", max(calc(0), calc(1)));
  return 0;
}
