#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1);
double EPS = 1e-7;
int INF = 1000000000;
int MOD = 1000000007;
int MAXINT = 2147483647;
long long INFLL = 1000000000000000000LL;
long long MAXLL = 9223372036854775807LL;
int mx[8] = {-1, 1, 0, 0, -1, -1, 1, 1};
int my[8] = {0, 0, -1, 1, -1, 1, -1, 1};
pair<int, int> lol[2][2005];
int s[2];
int n, X;
int go(int turn) {
  int x = X;
  priority_queue<int> pq[2];
  int it[2] = {1, 1};
  while (it[turn] <= s[turn] && lol[turn][it[turn]].first <= x) {
    pq[turn].push(lol[turn][it[turn]].second);
    it[turn]++;
  }
  int ret = 0;
  while ((int)pq[turn].size()) {
    ret++;
    x += pq[turn].top();
    pq[turn].pop();
    turn = !turn;
    while (it[turn] <= s[turn] && lol[turn][it[turn]].first <= x) {
      pq[turn].push(lol[turn][it[turn]].second);
      it[turn]++;
    }
  }
  return ret;
}
int main() {
  scanf("%d%d", &n, &X);
  for (int(a) = (1); (a) <= (n); (a)++) {
    int t, h, m;
    scanf("%d%d%d", &t, &h, &m);
    lol[t][++s[t]] = make_pair(h, m);
  }
  sort(lol[0] + 1, lol[0] + s[0] + 1);
  sort(lol[1] + 1, lol[1] + s[1] + 1);
  cout << max(go(0), go(1)) << endl;
}
