#include <bits/stdc++.h>
int max(int a, int b) { return a > b ? a : b; }
using namespace std;
int t[2000], h[2000], m[2000];
int n, x;
int solve(int tt) {
  int vis[2000] = {0};
  int c = 0;
  int xx = x;
  while (1) {
    int ind = -1;
    int bm = 0;
    for (int i = 0; i < n; i++) {
      if (!vis[i] && t[i] == tt && bm < m[i] && xx >= h[i]) {
        bm = m[i];
        ind = i;
      }
    }
    if (ind == -1) break;
    vis[ind] = 1;
    xx += bm;
    c++;
    tt ^= 1;
  }
  return c;
}
int main() {
  cin >> n >> x;
  for (int i = 0; i < n; i++) {
    cin >> t[i] >> h[i] >> m[i];
  }
  int c1 = solve(0);
  int c2 = solve(1);
  cout << max(c1, c2);
  return 0;
}
