#include <bits/stdc++.h>
using namespace std;
vector<long long> cnt[105], v[100005];
bitset<1005> ok, is;
long long a[100005], dis[100005];
long long ans = 2147483647;
void DFS(long long now, long long fa, long long d) {
  is[now] = 1;
  ok[now] = 1;
  dis[now] = d;
  for (long long i : v[now]) {
    if (ok[i] && i != fa) {
      ans = min(1LL * ans, 1LL * dis[now] - dis[i] + 1);
    }
    if (!ok[i]) DFS(i, now, d + 1);
  }
  ok[now] = 0;
}
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  long long n;
  cin >> n;
  vector<long long> g;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] != 0) g.push_back(a[i]);
  }
  n = g.size();
  for (long long i = 1; i <= n; i++) a[i] = g[i - 1];
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j < 63; j++) {
      if (a[i] & (1LL << j)) {
        cnt[j].push_back(i);
      }
    }
  }
  for (long long i = 0; i < 63; i++) {
    if (cnt[i].size() >= 3) {
      return cout << "3" << '\n', 0;
    }
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = i + 1; j <= n; j++) {
      if ((a[i] & a[j]) != 0) {
        v[i].push_back(j);
        v[j].push_back(i);
      }
    }
  }
  for (long long i = 1; i <= n; i++) {
    if (!is[i]) DFS(i, 0, 1);
  }
  if (ans == 2147483647)
    cout << -1 << '\n';
  else
    cout << ans << '\n';
  return 0;
}
