n = int(input())
a = list(map(int, input().split()))

count = 0

for i in range(n-1):
    while True:
        if a[i] <= a[i+1]:
            break
        else:
            a[i+1] += 1
            count += 1

print(count)