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

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

    int n, massiv[100000], index, groshi = 0;
    cin >> n;
    index = n - 1;
    for (int i = 0; i < n; i++) {
        cin >> massiv[i];
    }
    while (massiv[index] > 0) {
        groshi = groshi + massiv[index];
        for (int i = 0; i < index; i++) {
            massiv[i]--;
        }
        massiv[index] = 0;
        index--;
    }
    cout << groshi;

}
