#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[2][2005];
int v[2][2005];
int ind[2];
int gao(int i, int x, int cnt) {
  int flag = 0;
  int tmpX = 0, tmpJ = 0;
  for (int j = 0; j < ind[i]; j++) {
    if (!v[i][j] && x >= a[i][j].first) {
      if (a[i][j].second > tmpX) {
        tmpX = a[i][j].second;
        flag = 1;
        tmpJ = j;
      }
    }
  }
  if (flag) {
    v[i][tmpJ] = 1;
    return gao(!i, x + tmpX, cnt + 1);
  } else {
    return cnt;
  }
}
int main() {
  int n, x;
  while (cin >> n >> x) {
    int a_i = 0, b_i = 0;
    for (int i = 0; i < n; i++) {
      int t, h, m;
      cin >> t >> h >> m;
      a[t][ind[t]].first = h;
      a[t][ind[t]++].second = m;
    }
    memset(v, 0, sizeof(v));
    int h = gao(1, x, 0);
    memset(v, 0, sizeof(v));
    int h1 = gao(0, x, 0);
    cout << max(h, h1) << endl;
  }
}
