#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
const long long mod = 1e9 + 7;
const int maxn = 5005;
const long long inf = 1e10;
int n;
long long b;
vector<int> g[maxn];
vector<long long> dp[maxn][2];
vector<long long> join(vector<long long> v, vector<long long> w) {
  int n = v.size();
  int m = w.size();
  vector<long long> res(n + m - 1, inf);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      res[i + j] = min(res[i + j], v[i] + w[j]);
    }
  }
  return res;
}
void dfs(int at) {
  for (int to : g[at]) {
    dfs(to);
    dp[at][0] = join(dp[at][0], dp[to][0]);
    dp[at][1] = join(dp[at][1], dp[to][1]);
  }
  for (int i = 0; i < int(dp[at][1].size()); i++) {
    dp[at][1][i] = min(dp[at][1][i], dp[at][0][i]);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> b;
  for (int i = 1; i <= n; i++) {
    int c, d;
    cin >> c >> d;
    dp[i][0].push_back(0);
    dp[i][0].push_back(c);
    dp[i][1].push_back(inf);
    dp[i][1].push_back(c - d);
    if (i > 1) {
      int p;
      cin >> p;
      g[p].push_back(i);
    }
  }
  dfs(1);
  for (int i = 1; i <= n; i++) {
    if (dp[1][1][i] > b) out(i - 1);
  }
  out(n);
  return 0;
}
