#include <fstream>
#include <queue>
#include <algorithm>

using namespace std;

ifstream input("Noixich.inp");
ofstream output("Noixich.out");

int main()
{
	int n;
	int count = 0;
	input >> n;
	deque <int> a(n);
	for (int i = 0; i < n; i++)
	{
		input >> a[i];
	}
	sort(a.begin(), a.end());
	while (a.size() != 1)
	{
		if (a.front() == 0) a.pop_front();
		a.front()--;
		a.pop_back();
		count++;
	}
	output << count;
	input.close();
	output.close();
	return 0;
}