#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
int n, m;
long long first, a[N];
bool vis[N];
int dem[100];
vector<pair<int, int> > adj[N];
int d[N];
int zz;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  if (fopen("test.inp", "r"))
    freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout);
  cin >> zz;
  for (int i = 1; i <= zz; i++) {
    cin >> first;
    if (first) {
      a[++n] = first;
      for (int j = 0; j < 64; j++)
        if ((1LL << j) & first) dem[j]++;
    }
  }
  int res = n + 123123;
  for (int i = 0; i < 64; i++)
    if (dem[i] > 2) {
      cout << 3 << endl;
      return 0;
    }
  assert(n <= 5000);
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++)
      if (a[i] & a[j]) {
        adj[i].push_back(pair<int, int>(j, ++m));
        adj[j].push_back(pair<int, int>(i, m));
      }
  assert(m <= 1000000);
  for (int i = 1; i <= n; i++) {
    queue<int> q;
    for (int j = 1; j <= n; j++) d[j] = -1;
    for (int j = 1; j <= m; j++) vis[j] = false;
    d[i] = 0;
    q.push(i);
    while (q.size()) {
      int u = q.front();
      q.pop();
      for (pair<int, int> first : adj[u]) {
        int v = first.first;
        int id = first.second;
        if (vis[id]) continue;
        vis[id] = true;
        if (d[v] != -1) {
          res = min(res, d[u] + d[v] + 1);
        } else {
          d[v] = d[u] + 1;
          q.push(v);
        }
      }
    }
  }
  if (res == n + 123123)
    cout << -1;
  else
    cout << res;
}
