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