n = int(input())
a = list(map(int,input().split()))
l = [0]*n

for i in range(1,n):
    while True:
        if a[i] >= a[i-1]:
            break
        else:
            a[i] += 1
            l[i] += 1
print(sum(l))

