#include <bits/stdc++.h>
using namespace std;
int n, x, xx;
vector<pair<int, int> > V[2];
bool use[2][2002];
int f(int mo) {
  memset(use, 0, sizeof(use));
  xx = x;
  for (int i = (1); i <= (n); i++) {
    int cm = mo ^ (i & 1), id = -1;
    for (int j = (0); j <= ((int)V[cm].size() - 1); j++) {
      if (use[cm][j]) continue;
      pair<int, int> cur = V[cm][j];
      if (cur.first <= xx && (id == -1 || cur.second > V[cm][id].second))
        id = j;
    }
    if (id == -1) return i - 1;
    use[cm][id] = 1;
    xx += V[cm][id].second;
  }
  return n;
}
int main() {
  scanf("%d %d", &n, &x);
  for (int i = (1); i <= (n); i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    V[a].push_back(make_pair(b, c));
  }
  printf("%d\n", max(f(0), f(1)));
  return 0;
}
