#include <bits/stdc++.h>
using namespace std;
int n, b, tot, sz[5010], head[5010], ver[5010], Next[5010], d[5010], c[5010],
    dp[5010][5010][2];
void add(int u, int v) {
  ver[++tot] = v;
  Next[tot] = head[u];
  head[u] = tot;
}
void dfs(int u) {
  sz[u] = 1;
  dp[u][0][0] = 0;
  dp[u][1][0] = c[u];
  dp[u][1][1] = c[u] - d[u];
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    dfs(v);
    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][0], dp[v][k][1]));
      }
    }
    sz[u] += sz[v];
  }
}
int main() {
  memset(dp, 0x3f, sizeof(dp));
  scanf("%d%d", &n, &b);
  for (int i = 1, fa; i <= n; i++) {
    scanf("%d%d", &c[i], &d[i]);
    if (i != 1) scanf("%d", &fa), add(fa, i);
  }
  dfs(1);
  for (int i = n; i >= 0; i--)
    if (dp[1][i][0] <= b || dp[1][i][1] <= b) {
      printf("%d\n", i);
      return 0;
    }
}
