#include <bits/stdc++.h>
using namespace std;
long long at[100005], a[100005];
int bmap[64];
vector<int> adj[100005];
int d[100005];
int bestans;
queue<int> bq;
int bfs(int f, int dst) {
  while (!bq.empty()) bq.pop();
  bq.push(f);
  d[f] = 1;
  while (!bq.empty()) {
    int bf = bq.front();
    bq.pop();
    for (auto it : adj[bf]) {
      if (bf == f && it == dst)
        continue;
      else if (bf == dst && it == f)
        continue;
      if (!d[it]) {
        bq.push(it);
        d[it] = d[bf] + 1;
      }
    }
  }
  return d[dst];
}
int main() {
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  int allz = 0;
  for (int i = 0; i < n; i++) {
    cin >> at[i];
    allz += (at[i] == 0ll);
    for (int j = 0; j < 64; j++) bmap[j] += ((at[i] >> j) & 1);
  }
  if (allz == n) {
    cout << "0\n";
    return 0;
  }
  int p = 0;
  for (int i = 0; i < n; i++) {
    if (at[i]) a[p++] = at[i];
  }
  n = p;
  bool found = false;
  for (int i = 0; i < 64; i++) {
    if (bmap[i] >= 3) {
      found = true;
      cout << 3 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      if (a[i] & a[j]) adj[i].push_back(j);
    }
  }
  bestans = n + n;
  for (int i = 0; i < n; i++) {
    for (auto k : adj[i]) {
      for (int j = 0; j < n; j++) d[j] = 0;
      int ret = bfs(i, k);
      if (ret) bestans = min(bestans, ret);
    }
  }
  if (bestans > n)
    cout << "-1" << endl;
  else
    cout << bestans << endl;
  return 0;
}
