#include<bits/stdc++.h>
#define int long long
#define endl "\n";

using namespace std;

int bin_pow(int a, int b) {
	if(b == 0) return 1;
	if(b == 1) return a;
	if(b % 2 == 0) {
		int temp = bin_pow(a, b / 2);
		return temp*temp;
	} else {
		return bin_pow(a, b-1) * a;
	}
}

int gcd(int a, int b) {
	if(b == 0) return a;
	else {
		return gcd(b, a % b);
	}
}

signed main() {
	
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	
	int n;
	cin >> n;
	int cost = 0;
	int buys = 0;
	vector<int> balls(1e8, 0);
	for(int i = 0; i < n; i++) {
		int temp;
		cin >> temp;
		balls[temp]++;
	}
	
	for(int i = n; i > 0; i--) {
		
		if(balls[i] == 0) continue;
		int j = i;
		if(j - buys <= 0) break;
		else {
			cost += (j - buys)*balls[i];
			buys += balls[i];
		}
		
	}
	
	cout << cost;
	
	return 0;
}