#include <bits/stdc++.h>

#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,tune=native")
using namespace std;
typedef long long ll;
typedef long double ld;

#define ff first
#define ss second
#define pb push_back
#define el "\n"
#define se " "

const ll N=1e6+9;
const ll INF=1e18;

ll n,m,a,b,c,d,k,kk,i,j,cnt,cnt1,res,res1,sum,sum1,val,cur;
ll A[N];
map<ll,ll>mp;
vector<ll>v;
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>A[i];
        mp[A[i]]++;
        if(mp[A[i]]==1) v.pb(A[i]);
    }
    sort(v.begin(),v.end());
    cnt=0;
    ll mn=INF;
    for(i=v.size()-1;i>=0;i--){
        a=v[i],b=mp[v[i]];
        if(a-cnt>0) sum+=(a-cnt)*b,cnt+=b;
    }
    cout<<sum;
}
