#include <bits/stdc++.h>

using namespace std;

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

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

    int cost = 0, start = 0;
    auto it = a.rbegin();
    while(start < it->first){
        cost += it->second*(it->first-start);
        start += it->second;
        it++;
    }

    cout << cost;

    return 0;
}