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

struct Balloon{
    int num;
    int dist;
};

void deliting(int num, vector<Balloon> &a){
    for(int i = 0; i < a.size(); i++){
        if (a[i].num < a[num].num && a[i].num != 1)
            a[i].num--;
        if (a[i].num > a[num].num)
            a[i].num++;
    }
    a[num].num = 1;
}

bool cmp(Balloon a, Balloon b){
    return b.num > a.num;
}

int main() {
    int n;
	cin >> n;
    vector <Balloon> a;
    int g, cnt = 0;
    Balloon myballon;
    for (int i = 0; i < n; i++){
        cin >> g;
        myballon = {g, i};
        a.push_back(myballon);
    }
    sort(a.begin(), a.end(), cmp);
    while (a[a.size() - 1].num != 1){
        deliting(a.size() - 1, a);
        cnt += a[a.size() - 1].dist + 1;
        sort(a.begin(), a.end(), cmp);
    }
    cout << cnt;
}