#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
const int nax = 5005;
const int inf = 1e9 + 5;
int cost[nax], discount[nax], parent[nax];
int always[nax][nax], better[nax][nax];
vector<int> children[nax];
int subtree[nax];
void mini(int& a, int b) { a = min(a, b); }
int main() {
  int n, money;
  scanf("%d%d", &n, &money);
  for (int i = 0; i <= n; ++i)
    for (int j = 1; j <= n; ++j) always[i][j] = better[i][j] = inf;
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &cost[i], &discount[i]);
    if (i != 1) {
      scanf("%d", &parent[i]);
      children[parent[i]].push_back(i);
    }
  }
  for (int i = n; i >= 1; --i) {
    debug() << " ["
            << "range(always[i], always[i] + n + 1)"
               ": "
            << (range(always[i], always[i] + n + 1)) << "] ";
    debug() << " ["
            << "range(better[i], better[i] + n + 1)"
               ": "
            << (range(better[i], better[i] + n + 1)) << "] ";
    subtree[i]++;
    for (int a = subtree[i]; a >= 1; --a)
      better[i][a] = min(inf, better[i][a - 1] + cost[i] - discount[i]);
    for (int a = subtree[i]; a >= 1; --a)
      mini(always[i][a], always[i][a - 1] + cost[i]);
    for (int j = 0; j <= subtree[i]; ++j) mini(better[i][j], always[i][j]);
    debug() << " ["
            << "range(always[i], always[i] + n + 1)"
               ": "
            << (range(always[i], always[i] + n + 1)) << "] ";
    debug() << " ["
            << "range(better[i], better[i] + n + 1)"
               ": "
            << (range(better[i], better[i] + n + 1)) << "] ";
    debug() << "--";
    for (int a = subtree[parent[i]]; a >= 0; --a)
      for (int b = 0; b <= subtree[i]; ++b) {
        mini(always[parent[i]][a + b], always[parent[i]][a] + always[i][b]);
        mini(better[parent[i]][a + b], better[parent[i]][a] + better[i][b]);
      }
    subtree[parent[i]] += subtree[i];
  }
  for (int j = n; j >= 0; --j)
    if (always[1][j] <= money || better[1][j] <= money) {
      printf("%d\n", j);
      return 0;
    }
  assert(false);
}
