/**
 * created by : Mostafa Wael (Phoenix)
 * problem name : shortest cycle 
 */
#include <bits/stdc++.h>
using namespace std;
int bfs(int source,int n,vector<long long>&v){
    vector<int>distance(n,-1),parent(n,-1);
    distance[source] = 0;
    queue<int>q;
    q.push(source);
    while(!q.empty()){
        int x=q.front(); q.pop();
        for(int y=0;y<n;y++){
            // y == x self cycle invalid , parent [x] == y cycle like 1->2->1 invalid , v[x]&v[y]==0 there is not edge between two nodes
            if(y==x||parent[x]==y||!(v[y]&v[x])) continue;
            if(~distance[y]) return distance[y]+distance[x]+1;// length of cycle 
            distance[y]=distance[x]+1;
            parent[y]=x;
            q.push(y);
        }
    }
    return 125;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    /**
     *  if i want to make an edge between two node then (&) between them at least = 1 -> (1) 
     *  for example : (worst case)
     *  0.....000000000000001
     *  0.....000000000000001
     *  0.....000000000000010
     *  0.....000000000000010
     *  0.....000000000000100
     *  0.....000000000000100
     *  ... 
     *  10......0000000000000
     *  100.....0000000000000
     *  log2(10^18) = 60 -> (2)
     *  from (1) and (2) 
     *  if the n is greater than 120 the answer should be = 3 (smallest cycle ex: 1->2->3->1)
     *  otherwise we can calculate it using BFS 
     */
    int n,ans=121; cin>>n;
    vector<long long> v;
    for(int i=0;i<n;i++){
        long long u;
        cin>>u;
        if(u){// corner case 
            if(v.size()<121) v.push_back(u);
            else {
                cout<<3;
                return 0;
            }
        }
    }
    n=v.size();
    for(int i=0;i<n;i++)
    ans=min(ans,bfs(i,n,v));
    cout<<(ans==121?-1:ans);
    return 0;
}
