#include <bits/stdc++.h>
using namespace std;
vector<int> G[110000];
int mi = 10000000;
void bfs(int v) {
  vector<int> vis(110000, 0);
  queue<pair<pair<int, int>, long long> > qp;
  qp.push({{v, v}, 1});
  vis[v] = 1;
  while (!qp.empty()) {
    auto now = qp.front();
    qp.pop();
    int np = now.first.first, fr = now.first.second, len = now.second;
    for (auto adj : G[np]) {
      if (adj == fr)
        continue;
      else if (vis[adj]) {
        mi = min(mi, len + vis[adj] - 1);
      } else {
        vis[np] = len;
        qp.push({{adj, np}, len + 1});
      }
    }
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> pos[100];
  for (int i = 0; i < n; i++) {
    long long t, p = 1;
    cin >> t;
    for (long long j = 0; j < 64; j++) {
      if (t & (p << j)) pos[j].push_back(i);
    }
  }
  vector<int> bf;
  for (int i = 0; i < 100; i++) {
    if (pos[i].size() > 2) {
      cout << 3 << endl;
      return 0;
    }
    if (pos[i].size() > 1) {
      int a = pos[i][0], b = pos[i][1];
      G[a].push_back(b);
      G[b].push_back(a);
      bf.push_back(a);
      bf.push_back(b);
    }
  }
  for (auto i : bf) {
    bfs(i);
  }
  if (mi == 10000000)
    cout << -1 << endl;
  else
    cout << mi << endl;
}
