#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 7;
const int inf = 0x3f3f3f3f;
struct node {
  int to, nex;
} edge[maxn];
int head[maxn], dp[maxn][maxn][2], S[maxn], cnt = 1;
int c[maxn], d[maxn];
void Add(int u, int v) {
  edge[cnt].to = v;
  edge[cnt].nex = head[u];
  head[u] = cnt++;
}
void DFS(int u) {
  S[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], v; i; i = edge[i].nex) {
    DFS((v = edge[i].to));
    for (int j = S[u]; j >= 0; j--) {
      for (int k = 0; k <= S[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]));
      }
    }
    S[u] += S[v];
  }
}
int main() {
  int n, m, z;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &c[i], &d[i]);
    if (i != 1) {
      scanf("%d", &z);
      Add(z, i);
    }
  }
  memset(dp, inf, sizeof(dp));
  DFS(1);
  for (int i = n; i >= 0; i--) {
    if (min(dp[1][i][0], dp[1][i][1]) <= m) {
      printf("%d\n", i);
      break;
    }
  }
  return 0;
}
