from sys import exit n=int(input()) P=list(map(int,input().split())) ind=P.index(n)+1 ans=n*(n+1)//2-2*ind print(max(ans,0))