#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int n;
    vector<int> A;
    A.resize(5);
    cin>>n;
    int64_t ans=0;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        if(a>n-1){
            ans+=a-(n-1);
            A[i]=n-1;
        }else{
            A[i]=a;
        }
    }
    sort(A.begin(),A.end(),greater<int>());
    if(n==1){
        ans+=0;
    }else if(n==2){
        ans+=1;
    }else if(n==3){
        ans+=3;
    }else if(n==4){
        if(A[2]==3){
            ans+=6;
        }else if(A[1]==3){
            ans+=5;
        }else{
            ans+=4;
        }
    }else{
        if(A[0]==4){
            if(A[3]==4){
                ans+=10;
            }else if(A[1]==4){
                ans+=A[2]+5;
            }else{
                if(A[4]==3){
                    ans+=8;
                }else{
                    ans+=A[1]+A[2]+1;
                }
            }
        }else{
            if(A[3]==3){
                ans+=A[3]+A[4]+1;
            }else if(A[1]==3){
                ans+=A[1]+A[2];
            }else{
                ans+=A[0]+A[1];
            }
        }
    }
    cout<<ans<<endl;
}