// #pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#define int long long
#define ft first
#define sc second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define GG cout << " OPA " << '\n';

using namespace std;

const int N = 3e5 + 5;
const int INF = 1e9;

int a[N];

void solve() {
    int n;
    cin >> n;
    int ans = 0, x = 0;
    map <int, int, greater <int> > mp;
    for (int i = 1; i <= n; i ++) {
        cin >> a[i];
        mp[a[i]] ++;
    }
    for (auto it : mp) {
        // cout << it.ft << ' ' << it.sc << '\n';
        if (it.ft - x <= 0) break;
        ans += (it.ft - x) * it.sc;
        x += it.sc; 
    }
    cout << ans;
}

main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cerr.tie(0);
    int test = 1;
    // cin >> test;
    while(test --) {
        solve();
    }
}