#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=1)
{
    if(lvl == 5) return 5; 
    for(auto& x : a)
    {
        x--;
        if(isSol(a)) return lvl;
        x++; x++;
        if(isSol(a)) return lvl;
        x--;
    }
    int sol;
    for(auto& x : a)
    {
        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;
}