#include <bits/stdc++.h>
using namespace std;
const int MAXN = 150;
int n;
bool Ady[MAXN][MAXN];
vector<long long> A;
int dist[MAXN];
bool pass[MAXN];
int min_path(int src, int dst) {
  for (int i = (0); i < (int)(n); i++) pass[i] = false;
  for (int i = (0); i < (int)(n); i++) dist[i] = 300;
  queue<int> Q;
  Q.push(src);
  dist[src] = 0;
  pass[src] = true;
  while (((int)Q.size())) {
    int p = Q.front();
    Q.pop();
    for (int q = (0); q < (int)(n); q++) {
      if (!Ady[p][q]) continue;
      if (pass[q]) continue;
      dist[q] = dist[p] + 1;
      pass[q] = true;
      Q.push(q);
    }
  }
  return dist[dst];
}
int main() {
  while (scanf("%d", &n) >= 1) {
    A.clear();
    for (int i = (0); i < (int)(n); i++) {
      long long x;
      scanf("%lld", &x);
      if (x) A.push_back(x);
    }
    n = ((int)A.size());
    if (n > 140) {
      printf("3\n");
      continue;
    }
    for (int i = (0); i < (int)(n); i++)
      for (int j = (0); j < (int)(n); j++)
        if (i != j) Ady[i][j] = (A[i] & A[j]);
    int ans = 200;
    for (int i = (0); i < (int)(n); i++)
      for (int j = (i + 1); j < (int)(n); j++)
        if (Ady[i][j]) {
          Ady[i][j] = Ady[j][i] = 0;
          ans = min(min_path(i, j) + 1, ans);
          Ady[i][j] = Ady[j][i] = 1;
        }
    if (ans < 200)
      printf("%d\n", ans);
    else
      printf("-1\n");
  }
  return 0;
}
