#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
int f[N][N][2], c[N], d[N], g[N][2], siz[N], ans;
struct node {
  int v, nxt;
} e[N << 1];
int first[N], cnt, n, b;
inline void add(int u, int v) {
  e[++cnt].v = v;
  e[cnt].nxt = first[u];
  first[u] = cnt;
}
inline void dfs(int u) {
  f[u][1][0] = c[u];
  f[u][1][1] = c[u] - d[u];
  f[u][0][0] = 0;
  siz[u] = 1;
  for (int i = first[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    dfs(v);
    siz[u] += siz[v];
    for (int j = siz[u]; j >= 0; --j) {
      for (int k = min(siz[v], j); k >= 0; --k) {
        if (j - k > siz[u] - siz[v]) break;
        f[u][j][0] = min(f[u][j][0], f[u][j - k][0] + f[v][k][0]);
        f[u][j][1] =
            min(f[u][j][1], f[u][j - k][1] + min(f[v][k][0], f[v][k][1]));
      }
    }
  }
  if (u == 1)
    for (int j = 0; j <= siz[u]; ++j)
      if (f[u][j][0] <= b || f[u][j][1] <= b) ans = max(ans, j);
}
int main() {
  scanf("%d%d", &n, &b);
  memset(f, 0x3f, sizeof(f));
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &c[i], &d[i]);
    int f;
    if (i >= 2) scanf("%d", &f), add(f, i);
  }
  dfs(1);
  cout << ans;
  return 0;
}
