import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) N = int(input()) P = list(map(int,input().split())) if N == 1: exit(print(0)) ans = 0 for i in range(1,N+1): p = P[i-1] if p == N: ans -= i else: ans += i print(max(0,ans))