#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<int> data(n);
    for(int i = 0; i < n; i++) {
        cin >> data[i];
    }

    int info;
    int sum = 0;
    for(int i = n - 1; i >= 0; i--) {
        if(data[i] <= 0) continue;
        info = data[i];
        if(info == 1) continue;

        sum += info;
        for(int l = i - 1; l >= 0; l--) {
            if(data[l] <= 0) continue;
            if(data[l] == info) continue;

            data[l]--;
            if(data[l] == 0) n--;
        }
    }
    cout << sum << endl;
}
