n = int(input()) p = list(map(int,input().split())) for i in range(n): if p[i] == n: idx = i+1 print(max(n*(n+1)//2 -2 * idx,0))