#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 5;
const int inf = 1e9 + 1;
const int mod = 1e9 + 7;
const double eps = 1e-15;
const int pw = 257;
int n, b, f[N][N], g[N][N], c[N], d[N], s[N];
vector<int> t[N];
void dfs(int v) {
  ++s[v];
  for (int i = 0; i < int(t[v].size()); ++i) {
    int to = t[v][i];
    dfs(to);
    for (int j = 0; j <= s[v]; ++j) {
      c[j] = f[v][j];
      d[j] = g[v][j];
    }
    for (int j = 0; j <= s[v]; ++j) {
      for (int k = 0; k <= s[to]; ++k) {
        g[v][j + k] = min(g[v][j + k], d[j] + g[to][k]);
        if (j >= 1) f[v][j + k] = min(f[v][j + k], c[j] + f[to][k]);
      }
    }
    s[v] += s[to];
  }
  for (int j = 0; j <= s[v]; ++j) f[v][j] = min(f[v][j], g[v][j]);
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> b;
  for (int i = 1; i <= n; ++i) {
    for (int j = 2; j <= n; ++j) f[i][j] = g[i][j] = inf;
    int c, d;
    cin >> c >> d;
    f[i][1] = c - d;
    g[i][1] = c;
    if (i != 1) {
      int x;
      cin >> x;
      t[x].push_back(i);
    }
  }
  dfs(1);
  int ans;
  for (int j = 0; j <= n; ++j)
    if (f[1][j] <= b) ans = j;
  cout << ans;
  return 0;
}
