#include <bits/stdc++.h>
using namespace std::chrono;
using namespace std;
const int N = 1005;
const int K = 105;
const int Inf = 1000000000;
const long long InfL = 1000000000000000000LL;
const int MOD = 1000000007;
long long Abs(long long a) { return a < 0 ? -a : a; }
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
vector<pair<int, int>> a[2];
vector<bool> used[2];
int get(int i, int x) {
  int res = 0;
  for (;;) {
    int pos = -1;
    for (int j = 0; j < a[i].size(); ++j) {
      if (used[i][j] == false && a[i][j].first <= x) {
        if (pos == -1 || a[i][j].second > a[i][pos].second) pos = j;
      }
    }
    if (pos == -1) return res;
    x += a[i][pos].second;
    used[i][pos] = true;
    ++res;
    i ^= 1;
  }
}
bool comp(pair<int, int> a, pair<int, int> b) {
  if (a.first == b.first) return a.second > b.second;
  return a.first < b.first;
}
int main() {
  int n, x;
  cin >> n >> x;
  for (int i = 0; i < n; ++i) {
    int t, h, m;
    cin >> t >> h >> m;
    a[t].push_back(make_pair(h, m));
  }
  for (int i = 0; i < 2; ++i) sort(a[i].begin(), a[i].end(), comp);
  int ans = 0;
  for (int i = 0; i < 2; ++i) {
    for (int j = 0; j < 2; ++j) {
      used[j].assign(a[j].size(), false);
    }
    ans = max(ans, get(i, x));
  }
  cout << ans << endl;
  return 0;
}
