#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define st string
#define pb push_back
#define rt return
#define rv reverse
#define sr sort
#define si size()
#define en end()
#define be begin()
#define sc second
#define fr first
#define vl vector < ll >
#define vvl vector < vector < ll > >
#define vs vector < st >
#define vvs vector < vector < st > >
#define pall pair < ll , ll >
#define pasl pair < st , ll >
#define pals pair < ll , st >
using namespace std;
map < ll , ll > mp;
int main()
{
    ll n;
    cin >> n;
    vl v;
    for (int i=0;i<n;++i)
    {
      ll x;
      cin >> x;
      if (mp[x]==0)
          v.pb(x);
      ++mp[x];
    }
    sr(v.be,v.en);
    rv(v.be,v.en);
    ll ans=0,k=0;
    for (int i=0;i<v.si;++i)
    {
     if (v[i]-k>0)
     {
        ans+=mp[v[i]]*(v[i]-k);
       // cout << mp[v[i]]*(v[i]-k) << " _ l\n";
        k+=mp[v[i]];
     }else
     {
         cout << ans << "\n";
         return 0;
     }
    }
   cout << ans << "\n";
   return 0;
}
