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

aMax = max(a)

answer = 0
countOld = 0

for i,v in enumerate(a):
    if i != 0:
        count = 0
        while v + count < a[i-1] + countOld:
            count += 1
        answer += count
        countOld = count

print(answer)
