n=int(input()) P=list(map(int,input().split())) goukei = (1+n)*n//2 for idx, p in enumerate(P): if p==n: goukei-=2*(idx+1) print(max(0, goukei))