#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 5000 + 5;
int n, m;
int pa[maxn], pb[maxn];
int sz[maxn];
int d[maxn][maxn][2];
vector<int> g[maxn];
void dfs(int u) {
  sz[u] = 1;
  d[u][0][0] = 0, d[u][1][0] = pa[u], d[u][1][1] = pa[u] - pb[u];
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    dfs(v);
    for (int j = sz[u]; j >= 0; j--) {
      for (int k = 0; k <= sz[v]; k++) {
        d[u][j + k][0] = min(d[u][j + k][0], d[u][j][0] + d[v][k][0]);
        d[u][j + k][1] = min(d[u][j + k][1], min(d[u][j][1] + d[v][k][1],
                                                 d[u][j][1] + d[v][k][0]));
      }
    }
    sz[u] += sz[v];
  }
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 1; i <= n; i++) g[i].clear();
    for (int i = 1; i <= n; i++) {
      scanf("%d%d", &pa[i], &pb[i]);
      if (i > 1) {
        int x;
        scanf("%d", &x);
        g[x].push_back(i);
      }
    }
    memset(d, INF, sizeof(d));
    dfs(1);
    int i;
    for (i = 0; i <= n; i++) {
      if (min(d[1][i][0], d[1][i][1]) > m) break;
    }
    printf("%d\n", i - 1);
  }
  return 0;
}
