#include <bits/stdc++.h>
using namespace std;
void ob(vector<long long> &a, vector<long long> &b) {
  vector<long long> it(a.size() + b.size(), 1e15);
  for (int i = it.size() - 1; i >= 0; i--) {
    if (i < a.size()) it[i] = a[i];
    for (int q = max((long long)0, i - (long long)b.size());
         q < a.size() && q + 1 <= i; q++) {
      it[i] = min(it[i], a[q] + b[i - q - 1]);
    }
  }
  a = it;
}
pair<vector<long long>, vector<long long>> rek(vector<long long> &cen,
                                               vector<long long> &kyp,
                                               vector<vector<int>> &grap,
                                               long long now) {
  pair<vector<long long>, vector<long long>> pai;
  vector<long long> a{cen[now] - kyp[now]}, b{cen[now]};
  for (int i = 0; i < grap[now].size(); i++) {
    pai = rek(cen, kyp, grap, grap[now][i]);
    ob(a, pai.first);
    for (int q = 0; q < pai.second.size(); q++) {
      b.push_back(pai.second[q]);
    }
  }
  sort(b.begin(), b.end());
  vector<long long> pr{b[0]};
  for (int i = 1; i < b.size(); i++) {
    pr.push_back(b[i] + pr[i - 1]);
  }
  for (int i = 0; i < min(a.size(), b.size()); i++) {
    a[i] = min(a[i], pr[i]);
  }
  return pair<vector<long long>, vector<long long>>{a, b};
}
int main() {
  long long n, mon;
  cin >> n >> mon;
  vector<vector<int>> grap(n);
  vector<long long> cen(n), kyp(n);
  cin >> cen[0] >> kyp[0];
  for (int i = 1; i < n; i++) {
    int pr;
    cin >> cen[i] >> kyp[i] >> pr;
    grap[pr - 1].push_back(i);
  }
  vector<long long> it = rek(cen, kyp, grap, 0).first;
  for (int i = 0; i < it.size(); i++) {
    if (it[i] > mon) {
      cout << i << "\n";
      return 0;
    }
  }
  cout << n;
}
