#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 5010;
int n, b;
int c[maxn], d[maxn], sz[maxn];
vector<int> mp[maxn];
int dp[maxn][maxn][2];
inline void dfs(int x) {
  dp[x][0][0] = 0;
  dp[x][1][0] = c[x];
  dp[x][1][1] = c[x] - d[x];
  sz[x] = 1;
  for (register int i = 0; i < mp[x].size(); ++i) {
    dfs(mp[x][i]);
    for (register int j = sz[x]; j >= 0; --j) {
      for (register int k = 0; k <= sz[mp[x][i]]; ++k) {
        dp[x][j + k][0] =
            min(dp[x][j + k][0], dp[x][j][0] + dp[mp[x][i]][k][0]);
        dp[x][j + k][1] =
            min(dp[x][j + k][1],
                dp[x][j][1] + min(dp[mp[x][i]][k][0], dp[mp[x][i]][k][1]));
      }
    }
    sz[x] += sz[mp[x][i]];
  }
}
int main() {
  int x;
  scanf("%d%d", &n, &b);
  for (register int i = 1; i <= n; ++i) {
    scanf("%d%d", &c[i], &d[i]);
    if (i != 1) {
      scanf("%d", &x);
      mp[x].push_back(i);
    }
  }
  for (register int i = 1; i <= n; ++i) {
    for (register int j = 0; j <= n; ++j) {
      for (register int k = 0; k < 2; ++k) dp[i][j][k] = inf;
    }
  }
  dfs(1);
  for (register int i = n; i >= 0; --i) {
    if (dp[1][i][0] <= b || dp[1][i][1] <= b) {
      printf("%d\n", i);
      break;
    }
  }
  return 0;
}
