N = int(input()) P = list(map(int, input().split())) i = P.index(N) print(max(0, N * (N + 1)//2 - 2 * (i + 1)))