#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
const ll DIM = 1e5+7;

ll n,a[DIM];

map<ll,ll> M;
set<ll> S;
vector<ll> pos;

int main()
{
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i];
        M[a[i]]++;
        S.insert(a[i]);
    }

    ll ans = 0;
    ll mod = 0;

    for(auto to:S){
        pos.push_back(to);
    }
    reverse(pos.begin(),pos.end());



    for(int i=0;i<pos.size();i++){
        if(pos[i]-mod<=0)break;

        ll num = M[pos[i]];
        ans+=(pos[i]-mod)*num;
        mod+=num;

        //cout << ans << endl;
        //return 0;
    }
    cout << ans << endl;

    return 0;
}

