#include <bits/stdc++.h>
using namespace std;
struct candy {
  int t, h, m;
} c[2010];
bool cmp(candy a, candy b) { return a.h < b.h; }
int main() {
  int n, x, hmax;
  cin >> n >> x;
  int i, j;
  for (i = 0; i < n; ++i) {
    cin >> c[i].t >> c[i].h >> c[i].m;
  }
  sort(c, c + n, cmp);
  int mmax = 0;
  int flag;
  int tmmmm, t;
  int vis[2010];
  int ans1 = 0, ans2 = 0;
  memset(vis, 0, sizeof(vis));
  hmax = x;
  flag = 0;
  t = 1;
  for (i = 0; i < n && c[i].h <= hmax; ++i) {
    if (c[i].t != t && vis[i] == 0) {
      mmax = i;
      flag = 1;
      break;
    }
  }
  while (flag) {
    for (i = 0; i < n && c[i].h <= hmax; ++i) {
      if (c[mmax].m < c[i].m && c[i].t != t && vis[i] == 0) {
        mmax = i;
      }
    }
    vis[mmax] = 1;
    hmax += c[mmax].m;
    t = c[mmax].t;
    ans1++;
    flag = 0;
    for (i = 0; i < n && c[i].h <= hmax; ++i) {
      if (c[i].t != t && vis[i] == 0) {
        mmax = i;
        flag = 1;
        break;
      }
    }
  }
  memset(vis, 0, sizeof(vis));
  hmax = x;
  flag = 0;
  t = 0;
  for (i = 0; i < n && c[i].h <= hmax; ++i) {
    if (c[i].t != t && vis[i] == 0) {
      mmax = i;
      flag = 1;
      break;
    }
  }
  while (flag) {
    for (i = 0; i < n && c[i].h <= hmax; ++i) {
      if (c[mmax].m < c[i].m && c[i].t != t && vis[i] == 0) {
        mmax = i;
      }
    }
    vis[mmax] = 1;
    hmax += c[mmax].m;
    t = c[mmax].t;
    ans2++;
    flag = 0;
    for (i = 0; i < n && c[i].h <= hmax; ++i) {
      if (c[i].t != t && vis[i] == 0) {
        mmax = i;
        flag = 1;
        break;
      }
    }
  }
  cout << max(ans1, ans2) << endl;
  return 0;
}
