#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

	int n;

	cin >> n;

    vector <long long> v (n);

    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }

    long long res = 0, now = v[n - 1], shift = 0, shiftNow = 0; 

    for (int i = n - 1; i >= 0; i--) {
        if (v[i] != now) {
            now = v[i];
            shiftNow = shift;
        }

        if (v[i] - shiftNow > 0) res += (v[i] - shiftNow);
        shift++;
    }

    cout << res << endl;
}
