#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
int n, b;
int head[N], cnt;
int c[N], d[N];
struct edge {
  int to, next, s;
} e[N << 1];
void adde(int a, int b) {
  e[++cnt].to = b;
  e[cnt].next = head[a];
  head[a] = cnt;
}
int f[N][N][2], sz[N];
void dfs(int x) {
  sz[x] = 1;
  f[x][0][0] = 0;
  f[x][1][0] = c[x];
  f[x][1][1] = c[x] - d[x];
  for (int i = head[x]; i; i = e[i].next) {
    int v = e[i].to;
    dfs(v);
    for (int i = sz[x]; i >= 0; i--)
      for (int j = sz[v]; j; j--) {
        f[x][i + j][0] = min(f[x][i + j][0], f[x][i][0] + f[v][j][0]);
        f[x][i + j][1] = min(f[x][i + j][1], f[x][i][1] + f[v][j][1]);
        f[x][i + j][1] = min(f[x][i + j][1], f[x][i][1] + f[v][j][0]);
      }
    sz[x] += sz[v];
  }
}
int main() {
  scanf("%d%d", &n, &b);
  scanf("%d%d", &c[1], &d[1]);
  int u;
  for (int i = 2; i <= n; i++) scanf("%d%d%d", &c[i], &d[i], &u), adde(u, i);
  memset(f, 63, sizeof(f));
  dfs(1);
  for (int i = n; i >= 0; i--)
    if (f[1][i][1] <= b || f[1][i][0] <= b) printf("%d\n", i), exit(0);
  return 0;
}
