// Ignut

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

class Value {
    public:
        int v;
        int c;
};

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

	int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i ++)
        cin >> a[i];
    sort(a, a + n);

    vector <Value> v = {};
    int j = -1;
    for (int i = 0; i < n; i ++) {
        if (j == -1 || a[i] != v[j].v) {
            v.push_back({a[i], 1});
            j ++;
        }
        else
            v[j].c ++;
    }
    reverse(v.begin(), v.end());
    /*
    for (int i = 0; i < v.size(); i ++)
        cout << v[i].v << " : " << v[i].c << "\n";
    */
    ll ans = 0;
    ll sum = 0;
    j = 0;
    while (j < v.size() && v[j].v - sum > 0) {
        ll sum_now = sum;
        while (v[j].c) {
            ans += (v[j].v - sum_now);
            sum ++;
            v[j].c --;
            //cout << ans << ' ';
        }

        j ++;
    }

    cout << ans << "\n";
}
