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