#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <algorithm>

#define MAXN 100000

using namespace std;

int n,k,pom;

struct node
{
       int value;
       int sumdown;
       int level; //leaf=0
       node* parent;
};

int main(int argc, char *argv[])
{
    node* root=(node*)malloc(sizeof(node));
    node* a[MAXN+1];
    scanf("%d %d",&n,&k);
    scanf("%d",&pom);
    a[1]=(node*)malloc(sizeof(node));
    a[1]->value=pom;
    a[1]->sumdown=0;
    a[1]->parent=root;
    a[1]->level=-1;
    for(int i=2;i<=n;i++)
    {
            scanf("%d",&pom);
            a[i]=(node*)malloc(sizeof(node));
            a[i]->value=pom;
            a[i]->sumdown=0;
            a[i]->level=0;
    }
    for(int i=2;i<=n;i++)
    {
            scanf("%d",&pom);
            a[i]->parent=a[pom];
            a[pom]->level=-1;
    }
    /*check
    for(int i=2;i<=n;i++)
    {
            printf("index:%d value:%d sumdown:%d leaf:%d parent value:%d\n",i,a[i]->value,a[i]->sumdown,a[i]->leaf,a[i]->parent->value);
    }
    */
    int lvl=0; bool found=true;
    while(found)
    {
     found=false;
     //printf("a");
     for(int i=2;i<=n;i++)
     {
            if(a[i]->level==lvl)
            {
                        a[i]->sumdown+=a[i]->value;
                        if(a[i]->parent->level==-1 || a[i]->level+1 < a[i]->parent->level)  a[i]->parent->level=a[i]->level+1;
                        a[i]->parent->sumdown+=a[i]->sumdown;
                        found=true;
            }
     }
     lvl++;
    }
    a[1]->sumdown+=a[1]->value;
    //check
   /*  printf("index:%d value:%d sumdown:%d level:%d \n",1,a[1]->value,a[1]->sumdown,a[1]->level);
    for(int i=2;i<=n;i++)
    {
            printf("index:%d value:%d sumdown:%d level:%d parent value:%d\n",i,a[i]->value,a[i]->sumdown,a[i]->level,a[i]->parent->value);
    }*/
    //BUILT A TREE, NOW DESTROY IT
   
    node* dummy=(node*)malloc(sizeof(node));
    int potezi=0;
    while(1){
    //find indmax
    int max=0,indmax=0;
    for(int i=1;i<=n;i++)
    {
            if( a[i]->level!=-2 && a[i]->sumdown<=k && a[i]->sumdown>max) { max=a[i]->sumdown; indmax=i; }
    }
    if(indmax==1) { potezi++; break; }
    //vadimo indmax,updateujemo sume
    node* pom=a[indmax];
    int pomsum=pom->sumdown;
    while(pom!=root)
    {
                    pom->sumdown-=pomsum;
                    pom=pom->parent;
    }
    a[indmax]->parent=dummy;
    //refresh levels
    for(int i=1;i<=n;i++)
    {
            pom=a[i];
            while(pom!=root && pom!=dummy)
                pom=pom->parent;
            if(pom==dummy) a[i]->level=-2; //disconnected
    }
    potezi++;
            }
    
    printf("%d\n",potezi);
    //system("PAUSE");
    return 0;
}
