#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cstdio>

using namespace std;

const int MAX_N = 100005;

int n, k;
long long sum[MAX_N];
long long res[MAX_N];
vector<int> g[MAX_N];

void go(int node) {
    res[node] = 0;
    vector<long long> V;
    V.clear();
    for (int x = 0; x < g[node].size(); ++x) {
        int nnode = g[node][x];
        go(nnode);
        sum[node] += sum[nnode];
        res[node] += res[nnode];
        V.push_back(sum[nnode]);
    }
    sort(V.begin(), V.end());
    int p = V.size() - 1;
    while (sum[node] > k) {
        sum[node] -= V[p--];
        res[node]++;
    }
}

int main() {
    freopen("porez.in", "r", stdin);
    freopen("porez.out", "w", stdout);
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; ++i) scanf("%I64d", &sum[i]);
    for (int i = 0; i < n; ++i) g[i].clear();
    for (int i = 0; i < n; ++i) {
        int x; scanf("%d", &x);
        g[x - 1].push_back(i + 1);
    }
    go(0);
    printf("%I64d\n", res[0] + 1);
    return 0;
}
