n = int(input())
s = list(map(int, input().split()))
time = 1
count = s[-1]
for i in range(n-2, -1, -1):
    if s[i] == s[i-1]:
        count += max(0, temp)
    else:
        count += max(0, s[i]-time)
        if s[i] == s[i+1]:
            temp = s[i]-time
    time += 1
print(count)