#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;
	string str = "";
	for(int i = 0; i < n; i++) {
		char temp;
		cin >> temp;
		str += temp;
	}
	sort(str.begin(), str.end());
	int pr_numb = 0;
	int buys1 = 0;
	for(int i = str.length() - 1; i >= 0; i--) {
		int numb = str[i] - '0';
		if(numb - buys < 0) break;
		else {
			if(pr_numb != numb) {
				buys1 = buys;
			}
			cost += numb - buys1;
			buys++;
			pr_numb = numb;
		}
		
	}
 	
	cout << cost;
	
	return 0;
}