#include <bits/stdc++.h>
using namespace std;
const int maxn = 5010;
struct Edge {
  int v, nxt;
} edge[maxn];
int ecount, head[maxn];
void add(int u, int v) {
  ecount++;
  edge[ecount].v = v;
  edge[ecount].nxt = head[u];
  head[u] = ecount;
}
int n, m;
int a[maxn], b[maxn], c[maxn];
int f[maxn][maxn][2];
int siz[maxn];
void dfs(int now) {
  siz[now] = 1;
  f[now][0][0] = 0;
  f[now][1][0] = a[now];
  f[now][1][1] = a[now] - b[now];
  for (int p = head[now]; p; p = edge[p].nxt) {
    int v = edge[p].v;
    dfs(v);
    for (int i = siz[now]; i >= 0; i--) {
      for (int j = 0; j <= siz[v]; j++) {
        f[now][i + j][0] = min(f[now][i + j][0], f[now][i][0] + f[v][j][0]);
        f[now][i + j][1] = min(f[now][i + j][1], f[now][i][1] + f[v][j][1]);
        f[now][i + j][1] = min(f[now][i + j][1], f[now][i][1] + f[v][j][0]);
      }
    }
    siz[now] += siz[v];
  }
  return;
}
int main() {
  scanf("%d%d", &n, &m);
  scanf("%d%d", &a[1], &b[1]);
  for (int i = 2; i <= n; i++) {
    scanf("%d%d%d", &a[i], &b[i], &c[i]);
    add(c[i], i);
  }
  memset(f, 0x3f3f3f3f, sizeof(f));
  dfs(1);
  int ans = 0;
  for (int i = n; i >= 1; i--) {
    if (f[1][i][1] <= m || f[1][i][0] <= m) {
      ans = i;
      break;
    }
  }
  printf("%d", ans);
  return 0;
}
