#include <bits/stdc++.h>
using namespace std;
const long long mx = 1e5 + 666;
const long long mod = 1e9 + 7;
const long long inf = 1e7;
const int llg = 18;
long long power(long long a, long long b) {
  if (b == 0) return 1;
  if (b % 2)
    return a * power(a, b - 1) % mod;
  else
    return power(a * a % mod, b / 2);
}
long long n, cn = 1, a[mx], dis[mx], par[mx], ans = inf;
vector<long long> g[mx];
int dij() {
  for (int i = 1; i < cn + 1; i++) {
    fill(dis, dis + cn + 6, inf);
    fill(par, par + cn + 6, -1);
    queue<long long> q;
    dis[i] = 0;
    q.push(i);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (auto v : g[u]) {
        if (dis[v] == inf) {
          dis[v] = dis[u] + 1;
          par[v] = u;
          q.push(v);
        }
        if (v != par[u] && par[v] != u) ans = min(ans, dis[v] + dis[u] + 1);
      }
    }
  }
  if (ans == inf)
    return -1;
  else
    return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i < n + 1; i++) {
    long long x;
    cin >> x;
    if (x > 0) {
      a[cn] = x;
      cn++;
    }
  }
  if (cn > 128)
    cout << 3;
  else {
    for (int i = 1; i < cn + 1; i++) {
      dis[i] = inf;
      par[i] = -1;
      for (int j = i + 1; j < cn + 1; j++) {
        long long x = a[i] & a[j];
        if (x != 0) {
          g[i].push_back(j);
          g[j].push_back(i);
        }
      }
    }
    cout << dij();
  }
}
