#include <bits/stdc++.h>
using namespace std;
vector<int> types, height, mass;
bool used[2][2100];
vector<pair<int, int> > candies[2];
long long ans(int x_init, bool startCandy) {
  for (int i = 0, _i = (2); i < _i; ++i) {
    for (int j = 0, _j = (2100); j < _j; ++j) {
      used[i][j] = 0;
    }
  }
  long long score = 0;
  int mx_jump = x_init;
  bool br = false;
  while (true) {
    if (br) break;
    vector<pair<int, int> > curvec = candies[startCandy];
    for (int i = curvec.size() - 1; i >= -1; i--) {
      if (i == -1) {
        br = true;
        break;
      }
      if (used[startCandy][i] || mx_jump < curvec[i].second) {
        continue;
      } else {
        used[startCandy][i] = 1;
        mx_jump += curvec[i].first;
        score += 1;
        break;
      }
    }
    startCandy = !startCandy;
  }
  return score;
}
int main() {
  int n, x;
  cin >> n >> x;
  for (int i = 0, _i = (n); i < _i; ++i) {
    int t, h, m;
    cin >> t >> h >> m;
    candies[t].push_back(pair<int, int>(m, h));
  }
  sort(candies[0].begin(), candies[0].end());
  sort(candies[1].begin(), candies[1].end());
  long long ans1 = ans(x, 0);
  long long ans2 = ans(x, 1);
  long long ans = (ans1 > ans2) ? ans1 : ans2;
  cout << ans;
  return 0;
}
