#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
long long a[100010];
long long dis[201][201];
long long w[201][201];
int main() {
  int n;
  scanf("%d", &n);
  int cot = 1;
  for (int i = 0; i < 200; i++)
    for (int j = 0; j < 200; j++) dis[i][j] = w[i][j] = INF;
  for (int i = 0; i < n; i++) {
    long long x;
    scanf("%lld", &x);
    if (x == 0) continue;
    a[cot++] = x;
  }
  if (cot > 130)
    printf("3\n");
  else {
    long long ans = INF;
    for (int i = 1; i < cot; i++)
      for (int j = i + 1; j < cot; j++)
        if (a[i] & a[j]) dis[i][j] = dis[j][i] = w[i][j] = w[j][i] = 1;
    for (int k = 1; k <= cot; k++) {
      for (int i = 1; i < k; i++)
        for (int j = i + 1; j < k; j++) {
          ans = min(ans, dis[i][j] + w[i][k] + w[k][j]);
        }
      for (int i = 1; i <= cot; i++)
        for (int j = 1; j <= cot; j++)
          dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
    }
    if (ans == INF)
      printf("-1\n");
    else
      printf("%lld\n", ans);
  }
}
