#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int, int> i, pair<int, int> j) { return (i.second > j.second); }
int main() {
  int n, t, h, m, i;
  pair<int, int> candies[2][2001];
  bool used[2][2][2001];
  int x[2];
  scanf("%d %d", &n, &x[0]);
  x[1] = x[0];
  int size[] = {0, 0};
  for (i = 0; i < n; i++) {
    scanf("%d %d %d", &t, &h, &m);
    used[0][t][size[t]] = false;
    used[1][t][size[t]] = false;
    candies[t][size[t]++] = make_pair(h, m);
  }
  sort(candies[0], candies[0] + size[0], comp);
  sort(candies[1], candies[1] + size[1], comp);
  int starter;
  int sum[2];
  for (starter = 0; starter < 2; starter++) {
    sum[starter] = 0;
    t = starter;
    while (true) {
      for (i = 0; i < size[t]; i++) {
        if (candies[t][i].first <= x[starter] && !used[starter][t][i]) break;
      }
      if (i == size[t]) break;
      sum[starter]++;
      x[starter] += candies[t][i].second;
      used[starter][t][i] = true;
      t = (t + 1) % 2;
    }
  }
  printf("%d", max(sum[0], sum[1]));
  return 0;
}
