#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> a; int last = 0, uge = 0, potratili = 0;

void pristrii() {
	potratili += a[a.size()-1];
	uge++;

	for (int i = 0; i < a.size()-1; i++) {
		if (a[i] == 1) {
			uge += a[i];
			a[i] = 0;
		}
		else if(a[i] == 0) {}
		else if(a[i] != a[a.size() - 1]) {
			a[i]--;
		}
	}
	a.pop_back();
}

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

	int n, sum = 0;
	cin >> n;
	a.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		sum += a[i];
	}
	sort(a.begin(), a.end());
	for (uge; uge < sum && a.size() > 0; uge) {
		pristrii();
	}
	cout << potratili << '\n';
}