#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
int n, b, dp[N][N][2], sz[N], c[N], d[N], x;
vector<vector<int> > g;
void dfs(int v, int p = 0) {
  sz[v] = 1;
  dp[v][1][1] = c[v] - d[v];
  dp[v][1][0] = c[v];
  dp[v][0][0] = 0;
  for (auto to : g[v]) {
    if (to == p) continue;
    dfs(to, v);
    for (int i = sz[v]; i >= 0; i--) {
      for (int j = sz[to]; j >= 0; j--) {
        dp[v][i + j][1] =
            min(dp[v][i + j][1], dp[v][i][1] + min(dp[to][j][0], dp[to][j][1]));
        dp[v][i + j][0] = min(dp[v][i + j][0], dp[v][i][0] + dp[to][j][0]);
      }
    }
    sz[v] += sz[to];
  }
}
int main() {
  cin >> n >> b;
  g.resize(n + 1);
  for (int i = 1; i <= n; i++) {
    if (i == 1) {
      scanf("%d%d", &c[i], &d[i]);
      continue;
    }
    scanf("%d%d%d", &c[i], &d[i], &x);
    g[x].push_back(i);
  }
  memset(dp, 0x3f3f3f3f, sizeof(dp));
  dfs(1);
  for (int i = n; i >= 0; i--) {
    if (dp[1][i][1] <= b || dp[1][i][0] <= b) {
      cout << i << endl;
      return 0;
    }
  }
}
