long k;c,n,t,l,d[1<<18],u[1<<18];main(i){for(scanf("%d%ld",&n,&k);~scanf("%d",d+i++););for(i--;--i;)for(l+=!u[t=i];!u[t];t=d[t])u[t]=++c;n=!puts(k