#include <bits/stdc++.h>
#define pll pair<ll, ll>
#define x first
#define y second
using namespace std;
typedef long long ll;
const ll inf = 0x3fff3fff3fff3fff;
const ll N = 5e5+20;

signed main(){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
    map<ll, ll> c;
    ll n;
    cin >> n;
    for(ll i = 0;i<n;i++){
        ll z;
        cin >> z;
        c[z]++;
    }
    vector<pll> e;
    for(auto [i, j] : c) e.emplace_back(i, j);
    ll res=0, ch=0;
    for(;e.size();){
        if(e.back().x-ch<1) break;
        res+=e.back().y*(e.back().x-ch);
        ch+=e.back().y;
        e.pop_back();
    }
    cout<<res;
}
