n = int(input())
a = input().split()
money, step, anti_step = 0, 0, 0
last_tool = -1
while len(a) != 0:
    tool = int(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
    while int(a[0]) - step == 0:
        a.remove(a[0])
    last_tool = tool

print(money)
