#include <bits/stdc++.h>

using namespace std;

bool isSol(vector<int>& a)
{
    int b=a[0], c=0;
    for(auto& x : a) b = b & x, c = c ^ x;
    return b>0 && c>0;
}

int solve(vector<int>& a, int lvl=0)
{
    if(lvl == 4) return 4; 
    for(auto& x : a)
    {
        if(x>0)
        {
            x--;
            if(isSol(a)) return lvl+1;
            x++;
        }
        x++;
        if(isSol(a)) return lvl+1;
        x--;
    }
    int sol=100;
    for(auto& x : a)
    {
        if(x>0)
        {
            x--;
            sol = min(solve(a, lvl+1), sol);
            x++; 
        }
        x++;
        sol = min(solve(a, lvl+1), sol);
        x--;
    }
    return sol;
}

int main()
{
    ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
    int n; cin >> n;
    vector<int> vec;
    int br; while(n--) cin >> br, vec.push_back(br);
    cout << solve(vec) << endl; return 0;
}