#include <bits/stdc++.h>
using namespace std;
int main()
{
    freopen ("noixich.inp","r",stdin);
    freopen ("noixich.out","w",stdout);
    int n;
    cin>>n;
    int a[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    int i=1;
    int time=0;
    while(n>1)
    {
        if(a[i]+1 <n)
        {
            n=n-a[i]-1;
            time=time+a[i]*2;
            i++;
        }
        else
        {
            time=time+(n-1)*2;
            n=1;
        }
    }
    cout<<time/2;
}
