#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <cstdio>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <cstring>

using namespace std;
typedef long long ll;


int main(){
    ll n;
    cin >> n;
    
    vector<ll>a(n);
    for(int i = 0; i < n; i++)
        cin >> a[i];
    
    map<ll, ll> mp;
    for(auto i: a)
        mp[i]++;
    
    vector<pair<ll, ll>> d;
    
    for(auto i: mp)
        d.push_back(i);
    
    ll ans = 0, add = 0;
    
    for(int i = d.size() - 1; i >= 0; i--){
        ans += max(0ll, d[i].second * (d[i].first - add));
        
        
        add += d[i].second;
    }
    
    cout << ans << endl;
    
    return 0;
}
