#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define INF 1000000007
#define MAXN 200007

ll isPrime(ll n) {
    if (n < 2) {
        return false;
    }
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

ll binpow(ll n, ll p) {
    if (p == 0) {
        return 1;
    }
    if (p % 2 == 0) {
        ll b = binpow(n, p / 2);
        return b * b;
    }
    return binpow(n, p - 1) * n;
}

bool isPal(ll n) {
    string s = to_string(n);
    for (ll i = 0; i < s.length() / 2; i++) {
        if (s[i] != s[s.length() - i - 1]) {
            return false;
        }
    }
    return true;
}


void solve() {
    ll n;
    cin >> n;
    map<ll, ll> m;
    for (ll i = 0; i < n; i++) {
        ll x;
        cin >> x;
        m[x]++;
    }
    vector<pair<ll, ll>> a;
    for (auto i : m) {
        a.push_back({i.first, i.second});
    }
    ll mov = 0, ans = 0;
    for (ll i = a.size() - 1; i >= 0; i--) {
        if (a[i].first - mov <= 0) {
            break;
        }
        ans += (a[i].first - mov) * a[i].second;
        mov += a[i].second;
    }
    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie();

    ll t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
}