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