#include <algorithm>
#include <cstdio>
const int N=100005;
int a[N],fst[N],nxt[N],f[N],n,k,ans=0;
void addedge(int x,int y){
	nxt[y]=fst[x];fst[x]=y;
}
void dfs(int x){
	for (int i=fst[x];i;i=nxt[i]) dfs(i);
	if (++f[x]>=k && a[x]!=1) ans++,f[x]=0;
	f[a[x]]=std::max(f[a[x]],f[x]);
}
int main(){
	scanf("%d%d\n",&n,&k);f[1]=k;
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if (i!=1) addedge(a[i],i);
	}
	dfs(1);
	printf("%d\n",ans);
}