#include <bits/stdc++.h>
using namespace std;
struct candy {
  int t, h, m;
};
bool compare(candy a, candy b) {
  if (a.m == b.m) return a.h < b.h;
  return a.m > b.m;
}
candy a[2345];
int b[2345];
int main() {
  memset(b, 0, sizeof(b));
  int n, x;
  cin >> n >> x;
  for (int i = 0; i < n; i++) {
    cin >> a[i].t >> a[i].h >> a[i].m;
  }
  sort(a, a + n, &compare);
  long long cur = x * (long long)1, ans1 = 0, ans2 = 0, prev1 = 0, prev2 = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (b[j] != 1) {
        if (a[j].t != prev1) {
          if (cur >= a[j].h) {
            cur += a[j].m;
            ans1++;
            prev1 = a[j].t;
            b[j] = 1;
            break;
          }
        }
      }
    }
  }
  cur = x * (long long)1;
  memset(b, 0, sizeof(b));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (b[j] != 1) {
        if (a[j].t != prev2) {
          if (cur >= a[j].h) {
            cur += a[j].m;
            ans2++;
            prev2 = a[j].t;
            b[j] = 1;
            break;
          }
        }
      }
    }
  }
  cout << max(ans1, ans2);
}
