#include<bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
long long n,m,i,j,k,l,p,q,r,g,h,a[1000009],ans;
map <long long, long long> mp;
vector <pair <long long, long long > > v;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for(i=1;i<=n;i++)
    {
        cin >> k;
        mp[k]++;
    }
    for(auto it=mp.begin();it!=mp.end();it++)
    {
//        cout << it->first << " " << it->second << "\n";
          v.push_back({it->first, it->second});
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    k=0;
    for(i=0;i<v.size();i++)
    {
        if (k>=v[i].ff)
        {
            return cout << ans,0;
        }
        ans+=(v[i].ss*(v[i].ff-k));
        k+=v[i].ss;
    }
    cout << ans;
}
