#include <bits/stdc++.h>
using namespace std;
vector<int64_t> mul(const vector<int64_t> &a, const vector<int64_t> &b) {
  vector<int64_t> c(((int)(a).size()) + ((int)(b).size()) - 1, 1ll << 40);
  for (int i = 0; i < ((int)(a).size()); i++)
    for (int j = 0; j < ((int)(b).size()); j++) {
      c[i + j] = min(c[i + j], a[i] + b[j]);
    }
  return c;
}
vector<int64_t> gt(const vector<int64_t> &a, const vector<int64_t> &b) {
  vector<int64_t> c = a;
  for (int i = 0; i < ((int)(b).size()); i++) c[i] = min(c[i], b[i]);
  return c;
}
const int N = 5010;
vector<int> E[N];
vector<int64_t> a[N][2];
int n, b;
int64_t d[N], c[N];
void dfs(int u) {
  a[u][0] = {0, d[u]};
  vector<int64_t> tmp = {0};
  for (auto &v : E[u]) {
    dfs(v);
    a[u][0] = mul(a[u][0], a[v][0]);
    tmp = gt(mul(tmp, a[v][0]), mul(tmp, a[v][1]));
  }
  for (auto &e : tmp) e += d[u] - c[u];
  tmp.insert(tmp.begin(), 0ll);
  a[u][1] = tmp;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n >> b;
  for (int i = 1; i <= n; i++) {
    cin >> d[i] >> c[i];
    if (i != 1) {
      int x;
      cin >> x;
      E[x].push_back(i);
    }
  }
  dfs(1);
  auto z = a[5][0];
  for (int i = n; i >= 0; i--) {
    if (b >= min(a[1][0][i], a[1][1][i])) {
      cout << i << '\n';
      return 0;
    }
  }
  return 0;
}
