#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const unsigned gen_seed =
    std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937_64 gen(gen_seed);
int n, r;
std::vector<std::vector<int> > g;
const int INF = 1e6;
std::vector<int> d, p;
int main() {
  scanf("%d", &n);
  std::vector<long long> a(n);
  for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
  for (int i = 0; i < n; i++) {
    if (a[i] == 0) {
      swap(a[i], a[n - 1]);
      n--;
      i--;
    }
  }
  if (n > 120) {
    cout << 3;
    exit(0);
  }
  g.resize(n);
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (a[i] & a[j]) {
        g[i].push_back(j);
        g[j].push_back(i);
      }
    }
  }
  int ans = INF;
  for (int s = 0; s < n; s++) {
    d = std::vector<int>(n, INF);
    p = std::vector<int>(n, -1);
    d[s] = 0;
    priority_queue<pair<int, int> > q;
    q.push(make_pair(0, s));
    while (!q.empty()) {
      int v = q.top().second, cur_d = -q.top().first;
      q.pop();
      if (cur_d > d[v]) continue;
      for (size_t j = 0; j < g[v].size(); ++j) {
        int to = g[v][j], len = 1;
        if (d[v] + len < d[to]) {
          d[to] = d[v] + len;
          p[to] = v;
          q.push(make_pair(-d[to], to));
        }
      }
    }
    for (int u = 0; u < n; u++)
      for (auto v : g[u]) {
        if (u != p[v] && v != p[u]) ans = min(ans, d[u] + d[v] + 1);
      }
  }
  if (ans == INF) ans = -1;
  cout << ans;
}
