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