# dp[i][j] := i番目の人が選ばれたときの踏み台の最小値

def main():
    # INF = 10 ** 9
    N = int(input())
    A = list(map(int, input().split()))

    # initialize
    dp = [0] * (N + 10)
    dp[0] = A[0]

    res = 0
    for i in range(1, N):
        for j in range(N):
            # A[i-1] + h[i-1] < A[i] + h[i]
            if dp[i-1] <= (tmp := A[i] + j):
                # 条件が破れた時に一つ前の最小になるjを記録したい
                dp[i] = tmp
                res += j
                break
    print(res)

if __name__ == "__main__":
    main()