#include <cstdlib>
#include <iostream>
#include <stdio.h>
#define MAXN 100000

using namespace std;

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

int n,k,pom;
node* a[MAXN+1];
node* root=(node*)malloc(sizeof(node));
node* dummy=(node*)malloc(sizeof(node));

int main(int argc, char *argv[])
{
    freopen("porez.in","r",stdin);
    freopen("porez.out","w",stdout);
    
    //le building le tree
    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;
    }
    //le updating sumdowns
    int lvl=0; bool found=true;
    while(found)
    {
      found=false;
      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]->parent->level=a[i]->level+1;
                        a[i]->parent->sumdown+=a[i]->sumdown;
                        found=true;
            }
      }
      lvl++;
    }
    a[1]->sumdown+=a[1]->value;
    //le destroying a tree we just built, trololo
    int potezi=0, indmax=0;
    long long pomsum=0,max=-1;
    node* pomnode;
    while(1)
    {
            //le searching for optimal place to destroy, greedy
            max=-1; 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; }
            //le destroying indmax node, le updating sums
            pomnode=a[indmax]; pomsum=pomnode->sumdown;
             while(pomnode!=root)
             {
                    pomnode->sumdown-=pomsum;
                    pomnode=pomnode->parent;
             }
             a[indmax]->parent=dummy;
             //le refreshing levels, -2 <=> disconnected
             for(int i=1;i<=n;i++)
             {
                     pomnode=a[i];
                     while(pomnode!=root && pomnode!=dummy)
                                      pomnode=pomnode->parent;
                     if(pomnode==dummy) a[i]->level=-2; 
             }
     potezi++;
    }
    printf("%d\n",potezi);
    //system("PAUSE");
    return 0;
}
