#include <bits/stdc++.h>
using namespace std;
const int maxn = 5000 + 5;
const int INF = 1e9 + 5;
struct edge {
  int to, next;
  edge(int to = 0, int next = 0) : to(to), next(next) {}
} G[maxn];
int dp[maxn][maxn][2], c[maxn], d[maxn], head[maxn], tot, sz[maxn];
void init() {
  memset(head, -1, sizeof(head));
  tot = 0;
}
void addedge(int u, int v) {
  G[tot] = edge(v, head[u]);
  head[u] = tot++;
}
void upmin(int &a, int b) { a = min(a, b); }
void dfs(int u) {
  for (int i = 1; i < maxn; ++i) dp[u][i][0] = dp[u][i][1] = INF;
  sz[u] = 1;
  dp[u][0][1] = INF;
  dp[u][1][0] = c[u];
  dp[u][1][1] = c[u] - d[u];
  for (int i = head[u]; ~i; i = G[i].next) {
    int v = G[i].to;
    dfs(v);
    for (int i = sz[u]; i >= 0; --i) {
      for (int j = sz[v]; j > 0; --j) {
        upmin(dp[u][i + j][0], dp[u][i][0] + dp[v][j][0]);
        upmin(dp[u][i + j][1], dp[u][i][1] + min(dp[v][j][0], dp[v][j][1]));
      }
    }
    sz[u] += sz[v];
  }
}
int main() {
  init();
  int n, b;
  scanf("%d%d", &n, &b);
  for (int i = 1; i <= n; ++i) {
    int fa;
    scanf("%d%d", &c[i], &d[i]);
    if (i > 1) {
      scanf("%d", &fa);
      addedge(fa, i);
    }
  }
  dfs(1);
  int ans = 0;
  while (min(dp[1][ans + 1][0], dp[1][ans + 1][1]) <= b) ++ans;
  printf("%d\n", ans);
  return 0;
}
