import itertools n = int(input()) P = list(map(int,input().split())) ans = 0 use = [0]*(n+1) score = 0 for i in range(n)[::-1]: p = P[i] if p == n: score -= i+1 use[1] = 1 else: score += i+1 use[p+1] = 1 print(max(ans,score))