#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5002;
const int MOD = 1000000007;
const long long MODL = 1000000007100000007LL;
int n, b;
long long c[MAXN], d[MAXN];
vector<int> chi[MAXN];
vector<long long> dp[MAXN][2];
vector<long long> merge(vector<long long> &a, vector<long long> &b) {
  vector<long long> na(a.size() + b.size() - 1, MODL);
  for (int i = 0; i < a.size(); i++) {
    for (int j = 0; j < b.size(); j++) {
      na[i + j] = min(na[i + j], a[i] + b[j]);
    }
  }
  return na;
}
void dfs(int v) {
  dp[v][0] = {0, c[v]};
  dp[v][1] = {MODL, d[v]};
  for (int x : chi[v]) {
    dfs(x);
    dp[v][0] = merge(dp[v][0], dp[x][0]);
    dp[v][1] = merge(dp[v][1], dp[x][1]);
  }
  for (int i = 0; i < dp[v][1].size(); i++) {
    dp[v][1][i] = min(dp[v][1][i], dp[v][0][i]);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> b;
  for (int i = 1; i <= n; i++) {
    cin >> c[i] >> d[i];
    d[i] = c[i] - d[i];
    if (i > 1) {
      int p;
      cin >> p;
      chi[p].push_back(i);
    }
  }
  dfs(1);
  for (int i = n; i >= 0; i--) {
    if (dp[1][1][i] <= b) {
      cout << i << '\n';
      break;
    }
  }
  return 0;
}
