#include <stdio.h>
#include <queue>

using namespace std;

struct StrCvor
{
    int vred;
    int mindanaUpada;
    int mindanaNeUpada;
    int ostatakNeUpada;
    int prvoDete;
    int poslDete;
    int sledBrat;
} cvor [100000];

struct obrnutint
{
    int vred;
};

bool operator < (obrnutint a, obrnutint b)
{
    return b.vred < a.vred;
}

int n, k;
int a;

void Solve (int idx)
{
    int res = 0;
    int aktSuma = cvor [idx].vred;
    if (cvor [idx].prvoDete == -1)
    {
        cvor [idx].mindanaUpada = 1;
        if (cvor [idx].vred == k)
        {
            cvor [idx].mindanaNeUpada = 1;
            cvor [idx].ostatakNeUpada = 0;
        }
        else
        {
            cvor [idx].mindanaNeUpada = 0;
            cvor [idx].ostatakNeUpada = cvor [idx].vred;
        }
    }
    else
    {
        priority_queue <obrnutint> heap;
        int br = cvor [idx].prvoDete;
        while (br != -1)
        {
            Solve (br);
            if (cvor [br].mindanaNeUpada != cvor [br].mindanaUpada)
            {
                obrnutint s;
                s.vred = cvor [br].ostatakNeUpada;
                heap.push (s);
            }
            res += cvor [br].mindanaUpada;
            br = cvor [br].sledBrat;
        }
        while (!heap.empty () && aktSuma + heap.top ().vred <= k)
        {
            aktSuma += heap.top ().vred;
            heap.pop ();
            res--;
        }
        cvor [idx].mindanaNeUpada = res + 1;
        cvor [idx].mindanaUpada = res + 1;
        cvor [idx].ostatakNeUpada = 0;
        if (aktSuma != k)
        {
            cvor [idx].mindanaNeUpada--;
            cvor [idx].ostatakNeUpada = aktSuma;
        }
    }
}

int main ()
{
    FILE *in = fopen ("porez.in", "r");
    fscanf (in, "%d %d", &n, &k);
    fscanf (in, "%d", &a);
    cvor [0].vred = a;
    cvor [0].prvoDete = -1;
    cvor [0].poslDete = -1;
    cvor [0].sledBrat = -1;
    for (int i = 1; i < n; i++)
    {
        fscanf (in, "%d", &a);
        cvor [i].vred = a;
        cvor [i].prvoDete = -1;
        cvor [i].poslDete = -1;
        cvor [i].sledBrat = -1;
    }
    for (int i = 1; i < n; i++)
    {
        fscanf (in, "%d", &a);
        if (cvor [a - 1].prvoDete == -1)
        {
            cvor [a - 1].prvoDete = i;
            cvor [a - 1].poslDete = i;
        }
        else
        {
            cvor [cvor [a - 1].poslDete].sledBrat = i;
            cvor [a - 1].poslDete = i;
        }
    }
    fclose (in);
    Solve (0);
    FILE *out = fopen ("porez.out", "w");
    fprintf (out, "%d", cvor [0].mindanaUpada);
    return 0;
}
