#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
using namespace std;
const long long inf = 1ll << 60;
const long long iinf = 2147483647;
const long long mod = 1e9 + 7;
const long long maxn = 135;
const double PI = acos(-1);
long long pw(long long x, long long p, long long m = mod) {
  long long ret = 1;
  while (p > 0) {
    if (p & 1) {
      ret *= x;
      ret %= m;
    }
    x *= x;
    x %= m;
    p >>= 1;
  }
  return ret;
}
long long inv(long long a, long long m = mod) { return pw(a, m - 2); }
vector<long long> graph[maxn], par(maxn), lev(maxn);
long long shortest_c(long long x) {
  fill(lev.begin(), lev.end(), inf);
  fill(par.begin(), par.end(), -1);
  queue<long long> qu;
  qu.push(x);
  lev[x] = 0;
  par[x] = -2;
  long long ans = inf;
  while (qu.size()) {
    long long cx = qu.front();
    qu.pop();
    for (long long i = (0); i < ((long long)(graph[cx].size())); i++) {
      if (par[graph[cx][i]] != -1) {
        if (par[graph[cx][i]] != cx && lev[graph[cx][i]] <= lev[cx] &&
            par[cx] != graph[cx][i]) {
          ans = min(ans, lev[cx] + lev[graph[cx][i]] + 1);
        }
        continue;
      }
      par[graph[cx][i]] = cx;
      lev[graph[cx][i]] = lev[cx] + 1;
      qu.push(graph[cx][i]);
    }
  }
  return ans;
}
signed main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long N, n = 0;
  cin >> N;
  vector<long long> vc;
  for (long long i = (0); i < (N); i++) {
    long long x;
    cin >> x;
    if (x > 0) {
      n++;
      vc.push_back(x);
    }
  }
  if (n > 128) {
    cout << 3 << '\n';
    return 0;
  }
  if (n < 3) {
    cout << -1 << '\n';
    return 0;
  }
  for (long long i = (0); i < (n); i++) {
    for (long long j = (0); j < (n); j++) {
      if (i == j) {
        continue;
      }
      if ((vc[i] & vc[j]) != 0) {
        graph[i].push_back(j);
      }
    }
  }
  long long ans = inf;
  for (long long i = (0); i < (n); i++) {
    ans = min(ans, shortest_c(i));
  }
  if (ans == inf)
    cout << -1 << '\n';
  else
    cout << ans << '\n';
}
