N = int(input()) P = [0]+list(map(int,input().split())) ans = 0 for i in range(1,N+1): if P[i]!=N: ans += i else: ans -= i print(max(ans,0))