#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;

    map<int, int> a_m;
    for(int i = 0;i<n;i++){
        int x; cin >> x;
        a_m[x]++;
    }

    vector<int> s, c;

    for(auto& entry : a_m){
        s.emplace_back(entry.first);
        c.emplace_back(entry.second);
    }

    int m = static_cast<int>(a_m.size()), j = 0, cost = 0;
    for(int i = m-1;i>=0&&s[i]-j>0;i--){
        cost += (s[i]-j)*c[i];
        j += c[i];
    }

    cout << cost;

    return 0;
}