long k;c,n,d[1<<18],u[1<<18];int dfs(int v){u[v]?k-=c-1:(u[v]=1,c++,dfs(d[v]));}main(i){for(scanf("%d%ld",&n,&k);~scanf("%d",d+i++););for(i=0;i++