#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    int n;
    cin >> n;
    vector <int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a.rbegin(), a.rend());
    ll ans = 0, took = 0;
    for (int i = 0; i < n; i++)
        if (a[i] + 1 > took) {
            int ind = 0;
            while (a[i] == a[i + ind])
                ans += a[i] - took, ind++;
            //cout << a[i] << " " << ind << endl;
            i += ind - 1;
            took += ind;
        } else {
            break;
        } 
    cout << ans;
    return 0;
}