#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y) {
  long long res = 1LL;
  x = x % 1000000007;
  while (y > 0) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y >> 1;
    x = (x * x) % 1000000007;
  }
  return res % 1000000007;
}
long long inv(long long n) { return power(n, 1000000007 - 2) % 1000000007; }
long long cnt[70];
long long n;
long long a[200005];
vector<long long> g[200005];
void solve() {
  cin >> n;
  long long i, j;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    for (j = 0; j <= 60; j++)
      if (a[i] & (1LL << j)) cnt[j]++;
  }
  for (i = 0; i <= 60; i++)
    if (cnt[i] >= 3) {
      cout << "3\n";
      return;
    }
  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);
  while (a[n] == 0) n--;
  long long ans = 1e17;
  for (i = 1; i <= n; i++) {
    for (j = i + 1; j <= n; j++)
      if (a[i] & a[j]) {
        g[i].push_back(j);
        g[j].push_back(i);
      }
  }
  for (i = 1; i <= n; i++) {
    queue<long long> q;
    map<long long, long long> vis, dis, par;
    dis[i] = 0;
    q.push(i);
    vis[i] = 1;
    while (q.size()) {
      long long f = q.front();
      q.pop();
      for (auto x : g[f]) {
        if (vis[x] == 0) {
          vis[x] = 1;
          par[x] = f;
          dis[x] = 1 + dis[f];
          q.push(x);
        } else {
          if (par[f] == x) continue;
          ans = min(ans, dis[x] + dis[f] + 1);
        }
      }
    }
  }
  if (ans == 1e17) ans = -1;
  cout << ans << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  }
}
