#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 2001;
int num[N];
int main()
{
int n;
while(scanf("%d", &n) != EOF)
{
for(int i = 0; i < n; i++)
scanf("%d", &num[i]);
sort(num, num+n);
int len = n;
int tot = 0, i = 0;
while(tot != len-1)
{
if(num[i]){num[i]--; tot++;}
else{i++; len--;}
}
printf("%d\n", tot);
}
return 0;
}