#include <bits/stdc++.h>
using namespace std;
const int N = 5010, inf = 0x3f3f3f3f;
int n, m, cnt;
int dp[N][N][2], p[N], c[N], head[N], sz[N];
struct node {
  int next, to;
} edge[N << 1];
void addedge(int a, int b) {
  edge[cnt].to = b;
  edge[cnt].next = head[a];
  head[a] = cnt++;
  edge[cnt].to = a;
  edge[cnt].next = head[b];
  head[b] = cnt++;
}
void dfs(int u, int f) {
  sz[u] = 1;
  dp[u][0][0] = 0;
  dp[u][1][0] = p[u];
  dp[u][1][1] = p[u] - c[u];
  for (int i = head[u]; ~i; i = edge[i].next) {
    int v = edge[i].to;
    if (v == f) continue;
    dfs(v, u);
    for (int j = sz[u]; j >= 0; j--)
      for (int k = 0; k <= sz[v]; k++) {
        dp[u][j + k][0] = min(dp[u][j + k][0], dp[u][j][0] + dp[v][k][0]),
                  dp[u][j + k][1] =
                      min(dp[u][j + k][1],
                          dp[u][j][1] + min(dp[v][k][1], dp[v][k][0]));
      }
    sz[u] += sz[v];
  }
}
int main() {
  cnt = 0;
  memset(head, -1, sizeof(head));
  scanf("%d%d", &n, &m);
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++) dp[i][j][0] = dp[i][j][1] = 1e9 + 7;
  scanf("%d%d", &p[1], &c[1]);
  for (int i = 2; i <= n; i++) {
    int x;
    scanf("%d%d%d", &p[i], &c[i], &x);
    addedge(x, i);
  }
  dfs(1, 0);
  int ans = n;
  while (dp[1][ans][0] > m && dp[1][ans][1] > m) ans--;
  printf("%d\n", ans);
  return 0;
}
