#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const double pi = acos(-1.0);
const int Max = 2010;
const int INF = 1e9 + 7;
struct point {
  int h, m;
} points[2][Max];
int rem[2][Max];
int n, x;
int p[2] = {0, 0};
int solve(int type) {
  int H = x;
  int ans = 0;
  memset(rem, 0, sizeof rem);
  while (1) {
    int nt = -1;
    int m = 0;
    for (int i = 0; i < p[type]; i++) {
      if (points[type][i].h <= H && !rem[type][i] && points[type][i].m > m) {
        nt = i;
        m = points[type][i].m;
      }
    }
    if (nt == -1) return ans;
    ans++;
    rem[type][nt] = 1;
    H += m;
    type ^= 1;
  }
}
int main() {
  scanf("%d%d", &n, &x);
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    scanf("%d%d", &points[a][p[a]].h, &points[a][p[a]].m);
    p[a]++;
  }
  cout << max(solve(0), solve(1)) << endl;
  return 0;
}
