#include <iostream>
#include <cstdio>

using namespace std;

const int N = 100005;
int value[N], sum[N]; // value - samo ta; sum - celo podstablo
int prev[N];
bool done[N];
int n, k;

bool ddone(int x)
{
    if(done[x]) return true;
    if(prev[x] == -1) return false;
    return done[x] = ddone(prev[x]);
}

int main()
{
    freopen("porez.in","r",stdin);
    freopen("porez.out","w",stdout);

    scanf("%i %i",&n,&k);
    for(int i = 0; i < n; i++) scanf("%i",&value[i]);
    for(int i = 1; i < n; i++)
    {
        scanf("%i",&prev[i]);
        prev[i]--;
    }
    prev[0] = -1;

    for(int i = 0; i < n; i++) sum[i] = value[i];
    for(int i = 1; i < n; i++)
        for(int j = prev[i]; j != -1; j = prev[j])
            sum[j] += value[i];

    int res = 0;
    while(1)
    {
        res++;
        int max = 0;
        for(int i = 1; i < n; i++)
            if((sum[i] > sum[max] && sum[i] <= k) || sum[max] > k || ddone(max))
                max = i;
        if(ddone(max) || sum[max] > k) break;

        done[max] = true;
        for(int i = prev[max]; i != -1; i = prev[i])
            sum[i] -= sum[max];
    }

    printf("%i\n",res - 1);

    return 0;
}
