#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 5005;
const ll oo = 1e18;
int n, b;
int c[N], d[N], x[N];
vector<int> g[N];
vector<ll> dp[N];
vector<ll> sub[N];
void prec_sub(int u) {
  sub[u].push_back(c[u]);
  for (int v : g[u]) {
    prec_sub(v);
    int oldsz = (int)sub[u].size();
    sub[u].insert(sub[u].end(), sub[v].begin(), sub[v].end());
    inplace_merge(sub[u].begin(), sub[u].begin() + oldsz, sub[u].end());
  }
}
void dfs(int u) {
  dp[u].push_back(0);
  for (int v : g[u]) {
    dfs(v);
    if (dp[v].size() > dp[u].size()) swap(dp[u], dp[v]);
    size_t newsize = dp[u].size() + dp[v].size() - 1;
    while (dp[u].size() < newsize) dp[u].push_back(oo);
    for (int k = (int)dp[u].size() - 1; k >= 0; k--) {
      for (int j = 0; j < (int)dp[v].size() and j <= k; j++) {
        dp[u][k] = min(dp[u][k], dp[v][j] + dp[u][k - j]);
      }
    }
  }
  for (ll &val : dp[u]) val += c[u] - d[u];
  dp[u].insert(dp[u].begin(), 0LL);
  if (dp[u].size() != sub[u].size() + 1) {
    printf("deu ruim %d (%d %d)\n", u, (int)dp[u].size(), (int)sub[u].size());
    assert(0);
  }
  for (int i = 0; i < (int)sub[u].size(); i++) {
    dp[u][i + 1] = min(dp[u][i + 1], sub[u][i]);
  }
}
int main() {
  scanf("%d %d", &n, &b);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", c + i, d + i);
    if (i > 1) scanf("%d", x + i), g[x[i]].push_back(i);
  }
  prec_sub(1);
  for (int i = 1; i <= n; i++) {
    partial_sum(sub[i].begin(), sub[i].end(), sub[i].begin());
  }
  dfs(1);
  int ans = 0;
  for (int i = 0; i <= n; i++)
    if (dp[1][i] <= b) ans = i;
  printf("%d\n", ans);
}
