#include <bits/stdc++.h>

using namespace std;
#define SF scanf
#define PF printf
#define MAXN 105
#define DIV 10000000009
#define INF 100000000009
#define ll long long
#define ull unsigned long long
#define ld long double
//priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>> > Q;
ll n,k,mx,res,koef,price;
map<ll,ll>m;
vector<ll>v;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(ll i=1;i<=n;i++){
        cin>>k;
        if(m[k]==0){mx++;v.push_back(k);}
        m[k]++;

    }
sort(v.begin(),v.end());
koef=0;

for(ll i=mx-1;i>=0;i--){
    if(v[i]-koef<=0)break;
    res+=m[v[i]]*(v[i]-koef);
    koef+=m[v[i]];
}

/*res=0;
for(ll i=mx;i>=1;i--){
    if(m[i]==0)continue;
    if(i-koef<=0)break;

    res+=m[i]*(i-koef);
    koef+=m[i];

}*/
cout<<res<<"\n";











}

































/*      freopen("input.txt","r",stdin);
        ("output.txt","w",stdout);

        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
*/
