#include <bits/stdc++.h>
using namespace std;
long long n, a[100001], p[100001], h[100001], cnt[100], ans = INT_MAX;
vector<int> v[100001];
void dfs(int x) {
  for (auto u : v[x]) {
    if (p[u] && p[u] != p[x] - 1) {
      ans = min(ans, p[x] - p[u] + 1);
    } else if (!p[u])
      p[u] = p[x] + 1, dfs(u);
  }
  p[x] = 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    long long t = a[i], c = 0;
    while (t) {
      if (t & 1) cnt[c]++;
      t >>= 1;
      c++;
    }
  }
  for (int i = 0; i <= 64; i++)
    if (cnt[i] >= 3) {
      cout << 3;
      return 0;
    }
  for (int i = 0; i < n; i++)
    if (a[i])
      for (int j = i + 1; j < n; j++)
        if (a[j] && (a[i] & a[j])) v[i].push_back(j), v[j].push_back(i);
  for (int i = 0; i < n; i++)
    if (!h[i]) p[i] = 1, dfs(i);
  if (ans == INT_MAX)
    cout << -1;
  else
    cout << ans;
}
