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