N = int(input())
array = list(map(int, input().split()))
ans = 0
next = 1
a = True
while (a):
    a = False
    b = False
    for i in range(next,len(array)):
        if array[i] < array[i-1]:
            array[i] = array[i] + 1
            ans += 1
            a = True
            if b == False:
                b= True
                next = i

print(ans)
