a[51],j,s,y,c;main(i){for(;~scanf("%d",a+i);s=1)i+=s;for(;y=--i;s+=y-i?0:~c%2)for(c=1;(y=a[y])&&y