#include <bits/stdc++.h>
int const MAXN = 2020;
int t[MAXN], h[MAXN], m[MAXN], ids[MAXN];
char mask[MAXN];
int n, x;
int play(int tp) {
  memset(mask, 0, sizeof(mask));
  int str = x, cnt = 0;
  bool chg = true;
  while (chg) {
    chg = false;
    for (int i = 0; i < n; ++i) {
      if (t[ids[i]] == tp && h[ids[i]] <= str && mask[ids[i]] == 0) {
        str += m[ids[i]];
        ++cnt;
        tp = 1 - tp;
        chg = true;
        mask[ids[i]] = 1;
        break;
      }
    }
  }
  return cnt;
}
bool cmp_m(int a, int b) { return m[a] > m[b]; }
int main() {
  scanf("%d %d", &n, &x);
  for (int i = 0; i < n; ++i) {
    scanf("%d %d %d", &t[i], &h[i], &m[i]);
    ids[i] = i;
  }
  std::sort(ids, ids + n, cmp_m);
  int res = play(0);
  int tmp = play(1);
  if (tmp > res) res = tmp;
  printf("%d\n", res);
  return 0;
}
