#include <bits/stdc++.h>
using namespace std;
const int maxn = 5010;
struct edge {
  int v, next;
} e[maxn << 1];
int p[maxn], len, n, b, c[maxn], d[maxn], x, ans, size[maxn], dp[maxn][maxn][2];
void init() {
  memset(p, -1, sizeof p);
  len = 0;
}
void insert(int u, int v) {
  e[len].v = v;
  e[len].next = p[u];
  p[u] = len++;
}
void dfs(int u) {
  dp[u][0][0] = 0;
  dp[u][1][0] = c[u];
  dp[u][1][1] = c[u] - d[u];
  size[u] = 1;
  for (int i = p[u]; i != -1; i = e[i].next) {
    int v = e[i].v;
    dfs(v);
    for (int j = size[u]; j >= 0; j--) {
      for (int k = size[v]; k >= 0; 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] + dp[v][k][1]);
        dp[u][j + k][1] = min(dp[u][j + k][1], dp[u][j][1] + dp[v][k][0]);
      }
    }
    size[u] += size[v];
  }
}
int main() {
  init();
  scanf("%d %d", &n, &b);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &c[i], &d[i]);
    if (i > 1) {
      scanf("%d", &x);
      insert(x, i);
    }
  }
  memset(dp, 0x3f, sizeof dp);
  dfs(1);
  for (int i = n; i >= 1; i--) {
    if (dp[1][i][0] <= b || dp[1][i][1] <= b) {
      ans = i;
      break;
    }
  }
  printf("%d\n", ans);
  return 0;
}
