#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 3, M = 2 * N;
int n, b, c[N], d[N], p[N];
int dp[N][N][2];
int sz[N];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  scanf("%d%d", &n, &b);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", c + i, d + i);
    if (i) scanf("%d", p + i), --p[i];
  }
  for (int v = 0; v < n; ++v) {
    dp[v][0][1] = b + 1;
    dp[v][0][0] = 0;
    dp[v][1][0] = c[v];
    dp[v][1][1] = c[v] - d[v];
    sz[v] = 1;
    for (int x = 2; x <= n; ++x) dp[v][x][0] = dp[v][x][1] = b + 1;
  }
  for (int v = n - 1; v > 0; --v) {
    int u = p[v];
    for (int x = sz[u]; ~x; --x) {
      for (int y = sz[v]; ~y; --y) {
        dp[u][x + y][0] = min(dp[u][x + y][0], dp[u][x][0] + dp[v][y][0]);
        dp[u][x + y][1] =
            min(dp[u][x + y][1], dp[u][x][1] + min(dp[v][y][1], dp[v][y][0]));
      }
    }
    sz[u] += sz[v];
  }
  int ans;
  for (ans = n;; --ans)
    if (min(dp[0][ans][1], dp[0][ans][0]) <= b) break;
  printf("%d\n", ans);
}
