n = int(input())
a = input().split()
money, step, anti_step = 0, 0, 0
last_tool = -1
while step <= len(a) - 1:
    tool = int(a[-1-step])
    if tool == last_tool:
        anti_step += 1
    else:
        anti_step = 0
        if tool - step <= 0:
            break
    money += tool - step + anti_step
    step += 1
    last_tool = tool

print(money)
