#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int MAX_N = 200002;
const long long INF = 2000000000ll;
const long long LLINF = 1000000000000000000ll;
const int MOD = 1000000007;
vector<long long> a;
int cnt[65];
int d[MAX_N];
vector<int> b[MAX_N];
int n;
int bfs(int v) {
  for (int i = 0; i < (int)(n); i++) {
    d[i] = INF;
  }
  d[v] = 0;
  deque<int> q;
  q.push_back(v);
  while (!q.empty()) {
    int u = q.front();
    q.pop_front();
    for (int i : b[u]) {
      if (d[i] == INF) {
        d[i] = d[u] + 1;
        q.push_back(i);
      } else {
        if (d[i] == d[u]) {
          return 2 * d[u] + 1;
        } else {
          if (d[i] == d[u] + 1) {
            return d[i] * 2;
          }
        }
      }
    }
  }
  return n + 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.precision(10);
  cout << fixed;
  cin >> n;
  for (int i = 0; i < (int)(n); i++) {
    long long x;
    cin >> x;
    if (x == 0) {
      continue;
    }
    a.push_back(x);
    for (int j = 0; j < (int)(63); j++) {
      if (x & (1ll << j)) {
        cnt[j]++;
        if (cnt[j] > 2) {
          cout << "3\n";
          exit(0);
        }
      }
    }
  }
  n = a.size();
  assert(n < 200);
  for (int i = 0; i < (int)(n); i++) {
    for (int j = 0; j < (int)(n); j++) {
      if (i != j && (a[i] & a[j])) {
        b[i].push_back(j);
      }
    }
  }
  int res = n + 1;
  for (int i = 0; i < (int)(n); i++) {
    res = min(res, bfs(i));
  }
  if (res == n + 1) {
    cout << "-1\n";
  } else {
    cout << res << "\n";
  }
  return 0;
}
