N = int(input()) P = list(map(int, input().split())) if N == 1: print(0) exit() if N == 2 and P[0]==1: print(0) exit() i = P.index(N)+1 print(N*(N+1)//2-i*2)