n = int(input())
a = list(map(int, input().split()))
money, step, anti_step = 0, 0, 0
last_tool = -1
while len(a) != 0:
    tool = a.pop(-1)
    if tool == last_tool:
        anti_step += 1
    else:
        anti_step = 0
    money += tool - step + anti_step
    step += 1
    if len(a) == 0:
        break
    first = a[0]
    if first - step == 0:
        for i in range(a.count(first)):
            a.remove(first)
    last_tool = tool

print(money)