#include <bits/stdc++.h>
using namespace std;
int read() {
  int ans = 0, f = 1;
  char i = getchar();
  while (i < '0' || i > '9') {
    if (i == '-') f = -1;
    i = getchar();
  }
  while (i >= '0' && i <= '9') {
    ans = (ans << 1) + (ans << 3) + (i ^ 48);
    i = getchar();
  }
  return ans * f;
}
int n, s, cnt;
struct node {
  int v, w;
} a[5010];
struct edge {
  int to, next;
} e[10010];
int head[5010], son[5010];
int dp[5010][5010][2];
void add(int a, int b) {
  e[++cnt].to = b;
  e[cnt].next = head[a];
  head[a] = cnt;
}
void dfs(int u) {
  son[u] = 1;
  dp[u][1][0] = a[u].w;
  dp[u][1][1] = a[u].v;
  dp[u][0][0] = 0;
  for (int i = head[u]; i; i = e[i].next) {
    int to = e[i].to;
    dfs(to);
    for (int j = son[u]; j >= 0; --j)
      for (int k = 0; k <= son[to]; ++k) {
        dp[u][j + k][0] = (dp[u][j + k][0]) < (dp[u][j][0] + dp[to][k][0])
                              ? (dp[u][j + k][0])
                              : (dp[u][j][0] + dp[to][k][0]);
        dp[u][j + k][1] = (dp[u][j + k][1]) < (dp[u][j][1] + dp[to][k][1])
                              ? (dp[u][j + k][1])
                              : (dp[u][j][1] + dp[to][k][1]);
        dp[u][j + k][1] = (dp[u][j + k][1]) < (dp[u][j][1] + dp[to][k][0])
                              ? (dp[u][j + k][1])
                              : (dp[u][j][1] + dp[to][k][0]);
      }
    son[u] += son[to];
  }
}
int main() {
  (n = read());
  (s = read());
  n = n;
  memset(dp, 0x3f, sizeof(dp));
  (a[1].w = read());
  (a[1].v = read());
  a[1].v = a[1].w - a[1].v;
  for (int i = 2; i <= n; ++i) {
    (a[i].w = read());
    (a[i].v = read());
    a[i].v = a[i].w - a[i].v;
    int fa;
    (fa = read());
    add(fa, i);
  }
  dfs(1);
  for (int i = n; i >= 0; --i)
    if (dp[1][i][0] <= s || dp[1][i][1] <= s) printf("%d\n", i), exit(0);
}
