#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MOD = 1e9 + 7;
void solve(){
int n;
cin >> n;
vector<ll> a(n);
vector<vector<int>> c(70, vector<int>());
vector<set<int>> g(n, set<int>());
int ans = INT_MAX;
for(int i = 0; i < n; i++){
cin >> a[i];
bitset<70> b(a[i]);
for(int j = 0; j < 70 && ans == INT_MAX; j++){
if(b[j] == 1){
for(auto x: c[j]){
g[x].insert(i);
g[i].insert(x);
}
c[j].push_back(i);
}
if(c[j].size() == 3){
ans = 3;
}
}
}
if(ans == 3){
cout << 3 << "\n";
return;
}
auto bfs = [&](int x, int p) -> int {
vector<int> dist(n, INT_MAX);
dist[x] = 0;
queue<int> q;
q.push(x);
while(q.size()){
int y = q.front();
q.pop();
for(auto z: g[y]){
if(dist[z] == INT_MAX){
dist[z] = dist[y] + 1;
if(z == p)return dist[z];
q.push(z);
}
}
}
return INT_MAX - 1;
};
for(int i = 0; i < n; i++){
vector<int> q;
for(auto x: g[i]){
q.push_back(x);
}
for(auto x: q){
g[i].erase(x);
g[x].erase(i);
ans = min(ans, bfs(i, x) + 1);
g[i].insert(x);
g[x].insert(i);
}
}
if(ans != INT_MAX)cout << ans << "\n";
else cout << -1 << "\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
for(int i = 1; i <= t; i++){
solve();
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbGwgbG9uZyBsb25nCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IE1PRCA9IDFlOSArIDc7CgoKCnZvaWQgc29sdmUoKXsKCWludCBuOwoJY2luID4+IG47Cgl2ZWN0b3I8bGw+IGEobik7CgoJdmVjdG9yPHZlY3RvcjxpbnQ+PiBjKDcwLCB2ZWN0b3I8aW50PigpKTsKCXZlY3RvcjxzZXQ8aW50Pj4gZyhuLCBzZXQ8aW50PigpKTsKCWludCBhbnMgPSBJTlRfTUFYOwo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