#coding: utf-8
from collections import defaultdict
import sys

N = int(input())
A = [int(x) for x in input().split()]

step = 0

prev = 0

for a in A:
    if a < prev:
        step = max(step, prev-a + 1)
        a += step

    prev = a
#    print(a)

print(step)
