#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int maxn = 1e5 + 1;
const long double EPS = 1e-6;
const long double PI = 3.141592653589793;
long long a[maxn];
long long cnt[60];
vector<int> g[maxn];
set<int> ng[maxn];
vector<long long> non_zero;
bool used[maxn];
int d[maxn];
vector<int> cc[maxn];
vector<int> count1;
int shortest_cyc(int v) {}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    for (long long bit = 0; bit < 60; ++bit) {
      if (a[i] & (1ll << bit)) {
        cnt[bit]++;
      }
    }
  }
  for (long long bit = 0; bit < 60; ++bit) {
    if (cnt[bit] >= 3) {
      cout << 3;
      return 0;
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (a[i]) {
      non_zero.push_back(a[i]);
    }
  }
  for (int i = 0; i < non_zero.size(); ++i) {
    for (int j = i + 1; j < non_zero.size(); ++j) {
      if (non_zero[i] & non_zero[j]) {
        g[i].push_back(j);
        g[j].push_back(i);
        ng[i].insert(j);
        ng[j].insert(i);
      }
    }
  }
  int ans = INF;
  for (int i = 0; i < non_zero.size(); ++i) {
    for (int j = 0; j < g[i].size(); ++j) {
      int x = g[i][j];
      ng[i].erase(x);
      ng[x].erase(i);
      queue<int> q;
      q.push(i);
      for (int i = 0; i < non_zero.size(); ++i) {
        used[i] = 0;
        d[i] = -1;
        cc[i].clear();
      }
      used[i] = 1;
      d[i] = 0;
      while (!q.empty()) {
        int cur = q.front();
        q.pop();
        for (int to : ng[cur]) {
          if (!used[to]) {
            used[to] = 1;
            d[to] = d[cur] + 1;
            cc[d[to]].push_back(to);
            q.push(to);
          }
        }
      }
      if (d[x] != -1) {
        ans = min(ans, d[x] + 1);
      }
      ng[i].insert(x);
      ng[x].insert(i);
    }
  }
  if (ans != INF) {
    cout << ans;
  } else {
    cout << -1;
  }
}
