#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll n,res=INF;
vi a;

void dfs(int I,vp b){
	if(I==n){
		ll x=0;
		for(auto p:b) x+=p.second;
		res=min(res,x);
		return;
	}
	b.push_back({1<<I,a[I]});
	dfs(I+1,b);
	b.pop_back();
	int m=b.size();
	for(int i=0;i<1<<m;i++){
		int t=0,cnt=0;
		for(int j=0;j<m;j++) if(i&1<<j){
			if(t&b[j].first){
				t=-1;
				break;
			}
			t|=b[j].first;
			cnt++;
		}
		if(t==-1||cnt>a[I]) continue;
		vp c;
		if(cnt<a[I]) c.push_back({1<<I,a[I]-cnt});
		for(int j=0;j<m;j++){
			if(i&1<<j){
				P p=b[j];
				if(p.second>1){
					c.push_back({p.first+(1<<I),1});
					c.push_back({p.first,p.second-1});
				}
				else c.push_back({p.first+(1<<I),p.second});
			}
			else c.push_back(b[j]);
		}
		dfs(I+1,c);
	}
}

int main(){
	cin>>n;
	a=vi(n);
	for(auto &i:a) cin>>i;
	dfs(0,vp());
	cout<<res<<endl;
}
