ll n,k,p,q,t,a[3d5];{rd(n,k,((a+1))(n));for(n=k;p+=t=a[--n],t>1;);for(n=k;q+=t=a[++n],t>1;);k=a[k];wt(k?(k<2?max(p,q):p+q)+k:0);}