#include <bits/stdc++.h>

using namespace std;

using ll = long long int;

int main() {
    ll n;
    cin >> n;

    map<ll, ll> a_m;
    for(ll i = 0;i<n;i++){
        ll x; cin >> x;
        a_m[x]++;
    }

    vector<ll> s, c;

    for(auto& entry : a_m){
        s.emplace_back(entry.first);
        c.emplace_back(entry.second);
    }

    ll m = static_cast<ll>(a_m.size()), j = 0;
    ll cost = 0;

    for(ll i = m-1;i>=0&&s[i]-j>0;i--){
        cost += (s[i]-j)*c[i];
        j += c[i];
    }

    cout << cost;

    return 0;
}