N=int(input()) P=list(map(int,input().split())) print((N*(N+1))//2-(P.index(N))*2-2)