#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
int b, sz[5001], c[5001], d[5001], f[5001][5001][2];
vector<int> son[5001];
void dp(int x) {
  sz[x] = 1;
  f[x][1][0] = c[x];
  f[x][1][1] = c[x] - d[x];
  for (int i = 0; i < son[x].size(); i++) {
    int now = son[x][i];
    dp(now);
    for (int j = sz[x]; j >= 0; j--)
      for (int k = sz[now]; k; k--) {
        f[x][j + k][0] = min(f[x][j + k][0], f[x][j][0] + f[now][k][0]);
        if (j)
          f[x][j + k][1] =
              min(f[x][j + k][1], f[x][j][1] + min(f[now][k][0], f[now][k][1]));
      }
    sz[x] += sz[now];
  }
}
int main() {
  int n;
  scanf("%d%d", &n, &b);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &c[i], &d[i]);
    if (i > 1) {
      int x;
      scanf("%d", &x);
      son[x].push_back(i);
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) f[i][j][0] = f[i][j][1] = 1000000001;
  dp(1);
  for (int i = n; i >= 0; i--)
    if (min(f[1][i][0], f[1][i][1]) <= b) {
      printf("%d", i);
      break;
    }
  return 0;
}
