#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ft first
#define sd second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define point pair <int, int>

main()
{
    ios_base::sync_with_stdio(0);
    cin.tie();
    int n;
    map <int, int> cnt;
    cin >> n;
    for (int i = 0, x; i < n; i++)
    {
        cin >> x;
        cnt[x]++;
    }
    map <int, int> :: iterator it, start;
    start = cnt.begin();
    it = cnt.end();
    it--;
    start--;
    int ans = 0, k = 0;
    for (; it != start; it--)
    {
        int x = it->ft;
        x = max(0ll, x - k);
        ans += it->sd * x;
        k += it->sd;
    }
    cout << ans;

    return 0;
}
