#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

	int n;
	cin >> n;
    struct lkio {
        long long x, y;
    };
    lkio v[100008];
    int b = 0, a = 0, i = 0;
    for(i = 1; i <= n; i++){
        cin >> a;
        if(a > b) b = a;
        v[a].x++;
    }
    int c = 0, d = 0;
    for(i = b; i >= 1; i--){
        v[i].y = i;
    }
    for(i = b; i >= 1; i--){
        if(v[i].x > 0 && v[i].y - d > 0){
            c+=v[i].x * (v[i].y - d);
            d+=v[i].x;
        }
    }
    cout << c;
}
