#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, ans = 2e9;
  int64_t m;
  cin >> n;
  vector<int> V[61], G[n + 1];
  for (int i = 1; i <= n; ++i) {
    cin >> m;
    for (int j = 0; j <= 60; ++j)
      if ((m >> j) & 1) V[j].push_back(i);
  }
  for (int i = 0; i <= 60; ++i)
    if (V[i].size() >= 3) {
      cout << 3;
      return 0;
    }
  for (int i = 0; i <= 60; ++i) {
    if (V[i].size() <= 1) continue;
    G[V[i][0]].push_back(V[i][1]);
    G[V[i][1]].push_back(V[i][0]);
  }
  for (int i = 1; i <= n; ++i) {
    map<int, int> dis, par;
    queue<int> q;
    dis.insert({i, 0});
    q.push(i);
    while (!q.empty()) {
      int j = q.front();
      q.pop();
      for (auto it : G[j]) {
        if (!dis.count(it)) {
          dis.insert({it, 1 + dis[j]});
          par.insert({it, j});
          q.push(it);
        } else if (par[it] != j && par[j] != it)
          ans = min(ans, dis[j] + dis[it] + 1);
      }
    }
  }
  if (ans == 2e9) ans = -1;
  cout << ans;
}
