#include <bits/stdc++.h>
using namespace std;
inline void mini(int &x, int y) { x = min(x, y); }
const int MX = 5009;
int n, budget;
int price[MX], discount[MX];
int sz[MX];
vector<int> v[MX];
void Pdfs(int x) {
  sz[x] = 1;
  for (auto nxt : v[x]) {
    Pdfs(nxt);
    sz[x] += sz[nxt];
  }
}
int dp[2][MX][2];
int inf;
int memo[MX][MX][2];
void dfs(int x) {
  memo[x][0][0] = memo[x][0][1] = 0;
  for (auto nxt : v[x]) dfs(nxt);
  for (int j = 0; j < MX; j++) dp[0][j][0] = dp[0][j][1] = inf;
  dp[0][0][0] = 0;
  dp[0][1][0] = price[x];
  dp[0][1][1] = price[x] - discount[x];
  bool cur = 0;
  int upto = 1;
  for (auto nxt : v[x]) {
    cur ^= 1;
    upto += sz[nxt];
    for (int j = 0; j <= upto; j++) dp[cur][j][0] = dp[cur][j][1] = inf;
    for (int j = 0; j <= upto - sz[nxt]; j++)
      for (int i = 0; i <= sz[nxt]; i++) {
        mini(dp[cur][j + i][0], dp[cur ^ 1][j][0] + memo[nxt][i][0]);
        mini(dp[cur][j + i][1], dp[cur ^ 1][j][1] + memo[nxt][i][0]);
        mini(dp[cur][j + i][1], dp[cur ^ 1][j][1] + memo[nxt][i][1]);
      }
  }
  for (int j = 1; j <= sz[x]; j++) {
    dp[cur][j][1] = min(dp[cur][j][1], dp[cur][j][0]);
    memo[x][j][0] = dp[cur][j][0];
    memo[x][j][1] = dp[cur][j][1];
  }
}
int par[MX];
int main() {
  cin >> n >> budget;
  for (int j = 1; j <= n; j++) {
    scanf("%d %d", &price[j], &discount[j]);
    if (j > 1) scanf("%d", &par[j]);
  }
  inf = budget + 100;
  for (int j = 1; j <= n; j++) {
    v[par[j]].push_back(j);
  }
  for (int j = 0; j < MX; j++)
    for (int i = 0; i < MX; i++) memo[j][i][0] = memo[j][i][1] = inf;
  Pdfs(0);
  dfs(0);
  for (int j = n + 1; j; j--) {
    if (min(memo[0][j][0], memo[0][j][1]) <= budget) {
      cout << j - 1 << endl;
      return 0;
    }
  }
}
