n = int(input())
a_list = [int(x) for x in input().split()]

count = 0
max = a_list[0]

for a in a_list:
    for _ in range(n):
        if max > a:
            count += 1
            a += 1
    max = a
print(count)