/*
Petar 'PetarV' Velickovic
Task: Utaja poreza
*/

#include <stdio.h>
#include <queue>
#include <vector>
#define MAX_N 100001

using namespace std;

//ideja: greedy algoritam zasnovan na BFS-u
//Pri svakoj iteraciji odabiramo podstablo koje je najblize k po vrednosti.

int n;
long long k;

int T[MAX_N];

long long price[MAX_N];
long long spent[MAX_N];
long long val[MAX_N];
bool mark[MAX_N];

int sol=0;

struct Node
{
       vector<int> adj;
};
Node graf[MAX_N];

inline void UpdateSpent(int x, int amt)
{
       mark[x]=true;
       int xt=x;
       while (xt!=-1)
       {
         spent[xt]+=amt;
         xt=T[xt];
       }
}

inline void BFS()
{
     long long tmax=0;
     long long tpos=0;
     queue<int> bfs_q;
     bfs_q.push(1);
     while (!bfs_q.empty())
     {
           int xt=bfs_q.front();
           bfs_q.pop();
           if (price[xt]-spent[xt]<=tmax) break;
           if (price[xt]-spent[xt]<=k)
           {
             tmax=price[xt]-spent[xt];
             tpos=xt;
             if (xt==1) break;
           }
           for (int i=0;i<graf[xt].adj.size();i++)
           {
             if (!mark[graf[xt].adj[i]])
             {
               bfs_q.push(graf[xt].adj[i]);
             }
           }
     }
     UpdateSpent(tpos,tmax);    
     sol++;       
}

int main()
{
    freopen("porez.in","r",stdin);
    freopen("porez.out","w",stdout);
    T[1]=-1;
    scanf("%d%lld",&n,&k);
    for (int i=1;i<=n;i++)
    {
        scanf("%lld",&val[i]);
    }
    for (int i=2;i<=n;i++)
    {
        scanf("%d",&T[i]);
        graf[T[i]].adj.push_back(i);
    }
    price[1]=val[1];
    for (int i=n;i>=2;i--)
    {
        price[i]+=val[i];
        price[T[i]]+=price[i];
    }
    while (!mark[1])
    {
          BFS();
    }
    printf("%d\n",sol);
    //scanf("%d",&n);
    return 0;
}
