#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxm = 120;
const int maxn = 1e5 + 50;
int n, d, t;
long long a[maxn];
int g[maxm + 10][maxm + 10], dis[maxm + 10][maxm + 10];
int floyd() {
  for (int i = 1; i <= t; i++)
    for (int j = 1; j <= t; j++) dis[i][j] = g[i][j];
  int res = INF;
  for (int k = 1; k <= t; k++) {
    for (int i = 1; i < k; i++)
      for (int j = i + 1; j < k; j++) {
        if (dis[i][j] != INF && g[i][k] != INF && g[k][j] != INF)
          res = min(res, dis[i][j] + g[i][k] + g[k][j]);
      }
    for (int i = 1; i <= t; i++)
      for (int j = 1; j <= t; j++) {
        if (dis[i][k] != INF && dis[k][j] != INF)
          dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
      }
  }
  if (res == INF) return -1;
  return res;
}
int main() {
  memset(g, INF, sizeof(g));
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    long long b;
    scanf("%lld", &b);
    if (b) a[++t] = b;
  }
  if (t > maxm)
    puts("3");
  else {
    for (int i = 1; i <= t; i++)
      for (int j = i + 1; j <= t; j++) {
        if ((a[i] & a[j]) != 0) g[i][j] = g[j][i] = 1;
      }
    printf("%d", floyd());
  }
  return 0;
}
