#include <bits/stdc++.h>
using namespace std;

struct NODE{
	int src,dst,cap,weight;
};
bool operator < (const NODE &a,const NODE &b){
	return a.weight > b.weight;
}

int X[5],n;
map< multiset<set<int>> , long long> dp[5];

long long dfs(int p, multiset<set<int>> S ){
	if( p == n ){
		return 0;
	}
	int x = X[p];
	if( dp[p].count(S) ) return dp[p][S];
	long long ans = 1e12;
	vector< set<int> > uniq(S.begin(),S.end());
	uniq.erase(unique(uniq.begin(),uniq.end()),uniq.end());
	for(int j = 0 ; j < (1<<uniq.size()) ; j++){
		auto T = S;
		set<int> orS;
		int size = 0;
		for(int k = 0 ; k < uniq.size() ; k++){
			if( j >> k & 1 ){
				auto e = uniq[k];
				e.insert(p);
				T.erase(T.find(uniq[k]));
				T.insert(e);
				size += uniq[k].size();
				orS.insert(uniq[k].begin(),uniq[k].end());
			}
		}
		int c = __builtin_popcount(j);
		if( size == orS.size() && c <= x){
			for(int k = 0 ; k < min(5,x-c) ; k++){
				T.insert({p});
			}
			ans = min(dfs(p+1,T)+x-c,ans);
		}
	}
	return dp[p][S] = ans;
}

int main(){
	cin >> n;
	for(int i = 0 ; i < n ; i++){
		cin >> X[i];
	}
	cout << dfs(0,{}) << endl;
}