n = int(input()) P = list(map(int, input().split())) ans = n * (n + 1) // 2 ans -= 2 * (P.index(n) + 1) print(ans)