n = int(input()) p = list(map(int, input().split())) p = list(reversed(p)) takeda = [x for x in range(1, n+1)] ansT, ansS = 0, 0 for i in range(n): score = n-i for j in range(len(takeda)): if takeda[j] > p[i]: ansT += score takeda.remove(takeda[j]) break else: if takeda == p: takeda = takeda[1:] continue takeda = takeda[1:] ansS += score print(ansT - ansS)