import sys
sys.setrecursionlimit(10**9)

n = int(input())
A = list(map(int, input().split()))
count = 0


def func(a, cnt=0):
    global count
    for i in range(len(a)-1):
        if a[i] > a[i+1]:
            a[i+1] += 1
            cnt += 1
            count = max(cnt, count)
            func(a, cnt)
        else:
            continue
    return count


COUNT = func(A)
print(COUNT)