#include <bits/stdc++.h>
using namespace std;
const int LEN = (int)1e5;
int n;
long long a[LEN];
vector<int> g[60];
int bfs(int r, int t) {
  queue<int> q;
  static int d[LEN];
  memset(d, 0, sizeof d);
  q.push(r);
  d[r] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int j = 0; (1ll << j) <= a[u]; j++)
      if ((1ll << j) & a[u])
        for (auto v : g[j])
          if (!d[v] && !(v == t && u == r)) {
            d[v] = d[u] + 1;
            if (v == t) return d[v] > 2 ? d[v] : INT_MAX;
            q.push(v);
          }
  }
  return INT_MAX;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    for (int j = 0; (1ll << j) <= a[i]; j++)
      if ((1ll << j) & a[i]) g[j].push_back(i);
    ;
    ;
  }
  for (int i = 0; i < 60; i++)
    if ((int)(g[i]).size() >= 3) {
      cout << 3;
      return 0;
    }
  int ans = INT_MAX;
  for (int i = 0; i < 60; i++)
    if ((int)(g[i]).size() > 1) {
      a[g[i][0]] &= ~(1ll << i);
      ans = min(ans, bfs(g[i][0], g[i][1]));
      a[g[i][0]] |= 1ll << i;
    }
  cout << (ans < INT_MAX ? ans : -1);
  return 0;
}
