#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;

#define int long long


signed main() {
    int n;
    cin >> n;
    map<int, int> m;
    vector<int> pos;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        m[x]++;
        if (m[x] == 1)
            pos.push_back(x);
    }
    sort(pos.rbegin(), pos.rend());
//    cout << pos.size() << endl;
    int shift = 0;
    int ans = 0;
    for (int i = 0; i < pos.size(); i++) {
        if (pos[i] - shift < 1) {
            break;
        }
        ans += m[pos[i]] * (pos[i]-shift);
        shift += m[pos[i]];
    }
    cout<<ans<<endl;
    return 0;
}
