#include <bits/stdc++.h>
using namespace std;
const int maxn = 5000 + 5;
int n, b, c[maxn], d[maxn], son[maxn];
int dp[maxn][maxn][2], ans = 0;
bool vis[maxn];
vector<int> e[maxn];
void dfs(int pos) {
  son[pos] = 1;
  int siz = e[pos].size();
  for (int i = 0; i < siz; i++) {
    int to = e[pos][i];
    if (!vis[to]) {
      vis[to] = 1;
      dfs(to);
      vis[to] = 0;
      for (int j = son[pos]; j >= 0; j--)
        for (int k = 0; k <= son[to]; k++) {
          dp[pos][j + k][0] =
              min(dp[pos][j + k][0], dp[pos][j][0] + dp[to][k][0]);
          dp[pos][j + k][1] =
              min(dp[pos][j + k][1],
                  dp[pos][j][1] + min(dp[to][k][1], dp[to][k][0]));
        }
      son[pos] += son[to];
    }
  }
  return;
}
int main() {
  scanf("%d%d", &n, &b);
  memset(vis, false, sizeof(vis));
  memset(dp, 0x3f3f3f, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &c[i], &d[i]);
    dp[i][0][0] = 0;
    dp[i][1][0] = c[i];
    dp[i][1][1] = c[i] - d[i];
    if (i == 1) {
      int pre = 0;
      e[pre].push_back(1);
    }
    if (i >= 2) {
      int pre;
      scanf("%d", &pre);
      e[pre].push_back(i);
    }
  }
  dfs(1);
  for (int i = 0; i <= n; i++) {
    if (dp[1][i][0] <= b) ans = i;
    if (dp[1][i][1] <= b) ans = i;
  }
  printf("%d", ans);
  return 0;
}
