#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

#define rep(i,n) for(int i = 0; i < (int)(n); ++i)

bool check(vector<int> &v1, vector<int> &v2){
    vector<int> cnt(5);
    for(auto e : v1) ++cnt[e];
    for(auto e : v2) ++cnt[e];
    int dup = 0;
    for(int i = 0; i < 5; ++i) if(cnt[i] > 1) ++dup;
    return dup <= 1;
}

long long solve(int n, vector<int> &a){
    vector<vector<int>> v;
    vector<vector<int>> v2;
    rep(i,n)rep(j,i){
        v.push_back({j, i});
        rep(k,j){
            v2.push_back({k, j, i});
            rep(l,k){
                v2.push_back({l, k, j, i});
            }
        }
    }

    vector<vector<vector<int>>> v3(1);
    for(auto &vv : v2) v3.push_back({vv});
    for(auto &vv : v2) for(auto &vvv : v2) if(check(vv, vvv)) v3.push_back({vv, vvv});
    int tmp = 0;

    for(auto vx : v3)
        rep(S,1<<v.size()){
            vector<long long> cnt(n);
            int pop = 0;
            for(auto vvx : vx){
                pop += vvx.size()-1;
                for(auto e : vvx){
                    ++cnt[e];
                }
            }
            bool okok = true;
            for(int j = 0; j < (int)v.size(); ++j){
                if(~S >> j & 1) continue;
                for(auto vvx : vx) if(!check(vvx, v[j])) okok = false;
                for(auto e : v[j]) ++cnt[e];
                ++pop;
            }
            if(!okok) continue;
            bool ok = true;
            for(int j = 0; j < n; ++j) if(cnt[j] > a[j]) ok = false;
            if(!ok) continue;
            tmp = max(tmp, pop);
        }

    return accumulate(a.begin(), a.end(), 0ll) - tmp;
}

int main(){
    vector<int> a(5);
    int n;
    cin >> n;
    rep(i,n) cin >> a[i];
    cout << solve(n,a) << endl;
}