#include <bits/stdc++.h>
const int N = 5005;
using namespace std;
int dp[N][N][2], n, b, c[N], d[N], x, son[N];
vector<int> adj[N];
void dfs(int u) {
  son[u] = 1;
  dp[u][0][0] = 0;
  dp[u][1][0] = c[u];
  dp[u][1][1] = c[u] - d[u];
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    dfs(v);
    for (int j = son[u]; j >= 0; j--) {
      for (int k = 0; k <= son[v]; k++) {
        dp[u][j + k][0] = min(dp[u][j + k][0], dp[u][j][0] + dp[v][k][0]);
        dp[u][j + k][1] = min(dp[u][j + k][1], dp[u][j][1] + dp[v][k][1]);
        dp[u][j + k][1] = min(dp[u][j + k][1], dp[u][j][1] + dp[v][k][0]);
      }
    }
    son[u] += son[v];
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> b;
  cin >> c[1] >> d[1];
  for (int i = 2; i <= n; i++) {
    cin >> c[i] >> d[i] >> x;
    adj[x].push_back(i);
  }
  memset(dp, 0x3f3f3f3f, sizeof dp);
  dfs(1);
  int ans = 0;
  for (int i = n; i >= 0; i--) {
    if (dp[1][i][0] <= b || dp[1][i][1] <= b) {
      ans = i;
      break;
    }
  }
  cout << ans << '\n';
  return 0;
}
