R=range J=lambda:list(map(int,input().split())) N,*_=J() A=[0]+J() F=[0]*(N+1) a=0 for i in R(1,N+1): for c in R(1,3): j=i while F[j]