#include <bits/stdc++.h>
#define int long long
using namespace std;

map <int, int> am;
set <int> r;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

	int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int A;
        cin >> A;
        ++am[A];
        r.insert (A);
    }
    int s = 0, res = 0;
    while (!r.empty ()) {
        int v = *r.rbegin ();
        r.erase (v);
        if (v <= s) break;
        res += am[v] * (v - s);
        s += am[v];
    }
    cout << res << '\n';
}
