#include "stdio.h"
#include "stdlib.h"
//treci zad.
//hint za radoznalog citaoca: Sam bog sveti zna kako ovo radi :S 
int *b,*indexi,*temp,*tempb,*p,n,k;
long long *a;

void mergesort(int w, int q){
          int v=(w+q)/2;
          int k=v+1;
          int i;
          if (w!=v) mergesort(w,v);
          if (k!=q) mergesort(k,q);
          for(i=w;i<=v;i++) {temp[i]=indexi[i];tempb[i]=b[i];}
          for(i=w;i<=q;i++) if (w<=v) {
                            if (k>q) {indexi[i]=temp[w];b[i]=tempb[w];w++;}
                            else{
                                 if (tempb[w]<b[k]) {indexi[i]=temp[w];b[i]=tempb[w];w++;}
                                 else {indexi[i]=indexi[k];b[i]=b[k];k++;}
                            }                  
          }
}

void def_p(){
        int i,j,k=0;
        for(i=0;i<n;i++) p[i]=0;
        p[0]=1;
        for(i=1;i<n;i++) if(b[i]!=k) {k=b[i];p[k]=i;}
        p[n]=n;
        k=n-1;
        while(k) {if(p[k]==0) p[k]=p[k+1];k--;}     
}

int funk(int g){
          int i,maxchild,maxchildi,tmp;
          if(a[g]>k) {
                     maxchild=a[indexi[p[g]]];
                     maxchildi=indexi[p[g]];
                     for(i=p[g]+1;i<p[g+1];i++) if(a[indexi[i]]>maxchild) {maxchild=a[indexi[i]];maxchildi=indexi[i];}
          }
          else{tmp=a[g];
          a[g]=0;
          return tmp;
          }
          tmp=funk(maxchildi);
          a[g]-=tmp;
          return tmp;
}

void uvecaj(int in,int vr){
     a[in]+=vr;
     if(b[in]>-1) uvecaj(b[in],vr);
     }

int main(){
FILE *in=fopen("porez.in","r"),*out=fopen("porez.out","w");

     int s=0,i;
     fscanf(in,"%d %d",&n,&k);
     a=(long long *)malloc(n*sizeof(long long));
     indexi=(int *)malloc(n*sizeof(int));
     b=(int *)malloc(n*sizeof(int));
     temp=(int *)malloc(n*sizeof(int));
     tempb=(int *)malloc(n*sizeof(int));
     p=(int *)malloc(n*sizeof(int));
     for(i=0;i<n;i++) {fscanf(in,"%d",a+i);indexi[i]=i;}
     b[0]=-1;
     for(i=1;i<n;i++) {fscanf(in,"%d",b+i);b[i]--;if(b[i]) uvecaj(b[i],a[i]);a[0]+=a[i];}
     if (n>2) mergesort(1,n-1);
     def_p();
     while(a[0]) {s++;funk(0);}
     fprintf(out,"%lld\n",s);
    
fclose(in);fclose(out);return 0;
}
