#include <bits/stdc++.h>
using namespace std;
void preprocess(void) { return; }
vector<vector<int> > adj, adjj;
vector<int> vis;
int ans = 1000000007;
int bfss(int v) {
  queue<int> q;
  map<int, int> diss, viss, p;
  diss[v] = 0;
  q.push(v);
  viss[v] = 1;
  p[v] = -1;
  while (!q.empty()) {
    auto x = q.front();
    ;
    q.pop();
    for (auto y : adjj[x]) {
      if (p[x] == y) continue;
      if (viss[y]) {
        if (diss[y] == 0 && diss[x] == 1) continue;
        ans = min(ans, diss[y] + diss[x] + 1);
      } else {
        p[y] = x;
        q.push(y);
        viss[y] = 1;
        diss[y] = diss[x] + 1;
      }
    }
  };
  return ans;
}
int bfs(int v) {
  queue<int> q;
  map<int, int> p, diss, viss;
  p[v] = -1;
  diss[v] = 0;
  q.push(v);
  while (!q.empty()) {
    auto x = q.front();
    ;
    viss[x] = 1;
    q.pop();
    for (auto y : adjj[x]) {
      if (y == p[x]) continue;
      if (viss[y]) {
        ans = min(ans, diss[x] + diss[y] + 1);
      } else {
        p[y] = x;
        diss[y] = diss[x] + 1;
        q.push(y);
      }
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  preprocess();
  int n;
  cin >> n;
  adj.resize(63, vector<int>(0));
  adjj.resize(n, vector<int>(0));
  vis.resize(n, 0);
  vector<long long> a(n);
  for (auto i = (0); i < n; i++) cin >> a[i];
  for (auto i = (0); i < 63; i++) {
    for (auto j = (0); j < n; j++) {
      if ((1LL << i) & a[j]) {
        adj[i].push_back(j);
      }
    }
    if ((int)(adj[i]).size() >= 3) {
      cout << 3 << endl;
      return 0;
    }
  };
  for (auto i = (0); i < 63; i++) {
    if ((int)(adj[i]).size() > 1) {
      adjj[adj[i][0]].push_back(adj[i][1]);
      adjj[adj[i][1]].push_back(adj[i][0]);
    }
  };
  for (auto i = (0); i < n; i++) {
    if ((int)(adjj[i]).size() == 0) continue;
    ans = min(ans, bfs(i));
  }
  if (ans == 1000000007)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
