#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int N = 1e5;

int a[N];

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort (a, a + n);
    int prev = a[n - 1], cnt = 0;
    ll sum = 0;
    for (int i = n - 1; i >= 0; --i) {
        if (prev != a[i])
            cnt = n - i - 1;
        if (a[i] <= cnt) break ;
        sum += a[i] - cnt;
        prev = a[i];
    }
    cout << sum << "\n";
    return 0;
}
