#include <bits/stdc++.h>
using namespace std;
struct Nd {
  int height;
  int jump;
};
Nd nd_0[2005], nd_1[2005];
int cmp(const void *a, const void *b) {
  if ((*(Nd *)a).jump == (*(Nd *)b).jump) {
    return (*(Nd *)a).height > (*(Nd *)b).height ? 1 : -1;
  }
  return (*(Nd *)a).jump < (*(Nd *)b).jump ? 1 : -1;
}
int main() {
  int n, x, i, j, type, m_0 = 0, m_1 = 0, t_0 = 0, t_1 = 0;
  cin >> n >> x;
  for (i = 0; i < n; i++) {
    cin >> type;
    if (type == 0) {
      cin >> nd_0[m_0].height >> nd_0[m_0].jump;
      m_0++;
    } else {
      cin >> nd_1[m_1].height >> nd_1[m_1].jump;
      m_1++;
    }
  }
  qsort(nd_0, m_0, sizeof(Nd), cmp);
  qsort(nd_1, m_1, sizeof(Nd), cmp);
  int max = 0;
  int hash_0[2000] = {0}, hash_1[2000] = {0};
  while (1) {
    i = m_0;
    if (t_0 == 0) {
      for (i = 0; i < m_0; i++) {
        if (x >= nd_0[i].height && hash_0[i] == 0) {
          break;
        }
      }
    }
    j = m_1;
    if (t_1 == 0) {
      for (j = 0; j < m_1; j++) {
        if (x >= nd_1[j].height && hash_1[j] == 0) {
          break;
        }
      }
    }
    if (i < m_0 && j < m_1) {
      hash_0[i] = 1;
      hash_1[j] = 1;
      x += (nd_0[i].jump + nd_1[j].jump);
      max += 2;
    }
    if (i == m_0 && j < m_1) {
      hash_1[j] = 1;
      x += nd_1[j].jump;
      max++;
      t_0 = 0;
      t_1 = 1;
    }
    if (j == m_1 && i < m_0) {
      hash_0[i] = 1;
      x += nd_0[i].jump;
      max++;
      t_0 = 1;
      t_1 = 0;
    }
    if (i == m_0 && j == m_1) {
      break;
    }
  }
  cout << max << endl;
  return 0;
}
