#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ul = unsigned;
const int maxn = 100001;
const int maxk = 60;
int d[maxn], n;
unsigned res = -1;
ll a[maxn];
vector<int> v[maxk];
int cnt[maxn];
void dfs(int now, int level, int last = -1) {
  cnt[now] = true;
  if (d[now]) {
    res = min(res, ul(level - d[now]));
    return;
  }
  d[now] = level;
  for (int i = 0; i < maxk; ++i) {
    if (a[now] & (1ll << i)) {
      for (int &j : v[i]) {
        if (j != now and j != last) {
          dfs(j, level + 1, now);
        }
      }
    }
  }
  d[now] = 0;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < maxk; ++j) {
      if (a[i] & (1ll << j)) v[j].push_back(i);
    }
  }
  for (int i = 0; i < 60; ++i)
    if (v[i].size() > 2) return cout << 3 << '\n', 0;
  for (int i = 0; i < n; ++i)
    if (!cnt[i]) {
      dfs(i, 2);
    }
  cout << (int)res << '\n';
}
