N=int(input())
P=["*"]+list(map(int,input().split()))

k=P.index(N)
print(max(N*(N+1)//2-2*k,0))