#include <bits/stdc++.h>
using namespace std;
const int MAXI = 2005;
int n, x, type[MAXI], hei[MAXI], mass[MAXI];
int visited[MAXI];
int solve(int s) {
  int res = 0;
  memset(visited, 0, sizeof visited);
  int curx = x;
  bool cont = true;
  while (cont) {
    cont = false;
    int found = -1;
    for (int i = 0; i < n; i++) {
      if (!visited[i] && type[i] == s && curx >= hei[i] &&
          (found == -1 || mass[i] > mass[found]))
        found = i;
    }
    if (found != -1) {
      curx += mass[found];
      visited[found] = 1;
      res++;
      s = !s;
      cont = true;
    }
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> x;
  for (int i = 0; i < n; i++) {
    cin >> type[i] >> hei[i] >> mass[i];
  }
  cout << max(solve(0), solve(1)) << "\n";
  return 0;
}
