#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, x;
  cin >> n >> x;
  int t[n], h[n], m[n];
  for (int i = 0; i < n; i++) {
    cin >> t[i] >> h[i] >> m[i];
  }
  int res = 0;
  int k = 0;
  for (int j = 0; j < 2; j++) {
    vector<bool> vis(n, false);
    int ans = 0;
    int tx = x;
    while (1) {
      int cur = 0, pos = -1, type = -1;
      if (k == 1) {
        for (int i = 0; i < n; i++) {
          if (tx >= h[i] && !vis[i] && k != t[i]) {
            if (m[i] > cur) {
              cur = m[i];
              pos = i;
              type = t[i];
            }
          }
        }
        if (pos == -1) {
          break;
        }
        vis[pos] = true;
        ans++;
        k = type;
        tx += cur;
      } else {
        for (int i = 0; i < n; i++) {
          if (tx >= h[i] && !vis[i] && k != t[i]) {
            if (m[i] > cur) {
              cur = m[i];
              pos = i;
              type = t[i];
            }
          }
        }
        if (pos == -1) {
          break;
        }
        vis[pos] = true;
        ans++;
        k = type;
        tx += cur;
      }
    }
    k = 1;
    res = max(ans, res);
  }
  cout << res;
}
