#include <bits/stdc++.h>
using namespace std;
vector<int>edge[100005];
int dp[100005],x;
int rec(int v)
{
if(dp[v]>=0) return dp[v];
vector<int>vec;
for(int i=0;i<edge[v].size();i++)
{
vec.push_back(rec(edge[v][i]));
}
sort(vec.begin(),vec.end(),greater<int>());
int sum=0;
for(int i=0;i<vec.size();i++)
{
if(i == x) break;
sum+=vec[i];
}
return dp[v] = sum+1;
}
int main()
{
int n,m;
scanf("%d %d",&n,&m);
for(int i=2;i<=n;i++)
{
int x; scanf("%d",&x);
edge[x].push_back(i);
}
int lb=-1,ub=n;
while(ub-lb > 1)
{
int mid=(lb+ub)>>1;
x=mid;
memset(dp,-1,sizeof(dp));
rec(1);
if(dp[1] >= m) ub=mid;
else lb=mid;
}
printf("%d\n",ub);
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdmVjdG9yPGludD5lZGdlWzEwMDAwNV07CmludCBkcFsxMDAwMDVdLHg7CgppbnQgcmVjKGludCB2KQp7CglpZihkcFt2XT49MCkgcmV0dXJuIGRwW3ZdOwoJdmVjdG9yPGludD52ZWM7Cglmb3IoaW50IGk9MDtpPGVkZ2Vbdl0uc2l6ZSgpO2krKykKCXsKCQl2ZWMucHVzaF9iYWNrKHJlYyhlZGdlW3ZdW2ldKSk7Cgl9Cglzb3J0KHZlYy5iZWdpbigpLHZlYy5lbmQoKSxncmVhdGVyPGludD4oKSk7CglpbnQgc3VtPTA7Cglmb3IoaW50IGk9MDtpPHZlYy5zaXplKCk7aSsrKQoJewoJCWlmKGkgPT0geCkgYnJlYWs7CgkJc3VtKz12ZWNbaV07Cgl9CglyZXR1cm4gZHBbdl0gPSBzdW0rMTsKfQppbnQgbWFpbigpCnsKCWludCBuLG07CglzY2FuZigiJWQgJWQiLCZuLCZtKTsKCWZvcihpbnQgaT0yO2k8PW47aSsrKQoJewoJCWludCB4OyBzY2FuZigiJWQiLCZ4KTsKCQllZGdlW3hdLnB1c2hfYmFjayhpKTsKCX0KCWludCBsYj0tMSx1Yj1uOwoJd2hpbGUodWItbGIgPiAxKQoJewoJCWludCBtaWQ9KGxiK3ViKT4+MTsKCQl4PW1pZDsKCQltZW1zZXQoZHAsLTEsc2l6ZW9mKGRwKSk7CgkJcmVjKDEpOwoJCWlmKGRwWzFdID49IG0pIHViPW1pZDsKCQllbHNlIGxiPW1pZDsKCX0KCXByaW50ZigiJWRcbiIsdWIpOwp9