#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, cur_val, sum = 0;
    int a[100005];
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    sum += a[n];
    cur_val = 0;
    for(int i = n-1; i >= 1; i--)
    {
        if(a[i] != a[i+1])
            cur_val = n-i;
        if(a[i] > cur_val)
            sum += a[i] - cur_val;
    }
    cout << sum;
    return 0;
}
