#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') f = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    x = (x << 1) + (x << 3) + ch - '0';
  return x * f;
}
void chkmin(int &a, int b) { a > b ? a = b : 0; }
const int N = 5005;
vector<int> G[N];
int pri[N], dis[N], pre[N];
int size[N], dp[N][N][2];
void dfs(int u) {
  size[u] = 1;
  dp[u][0][0] = 0;
  dp[u][1][0] = pri[u];
  dp[u][1][1] = pri[u] - dis[u];
  for (int v : G[u]) {
    dfs(v);
    for (int i = size[u]; ~i; --i)
      for (int j = 0; j <= size[v]; ++j) {
        chkmin(dp[u][i + j][0], dp[u][i][0] + dp[v][j][0]);
        chkmin(dp[u][i + j][1], dp[u][i][1] + dp[v][j][1]);
        chkmin(dp[u][i + j][1], dp[u][i][1] + dp[v][j][0]);
      }
    size[u] += size[v];
  }
}
int main() {
  int n = read();
  int m = read();
  for (int i = 1; i <= n; ++i) {
    pri[i] = read();
    dis[i] = read();
    if (i > 1) {
      pre[i] = read();
      G[pre[i]].push_back(i);
    }
  }
  memset(dp, 0x3f, sizeof(dp));
  dp[1][0][0] = 0;
  dfs(1);
  for (int i = n; ~i; --i)
    if (dp[1][i][1] <= m || dp[1][i][0] <= m) return printf("%d\n", i), 0;
  return 0;
}
