#include <bits/stdc++.h>
using namespace std;
int n;
int f[205][205];
long long a[205];
int main() {
  scanf("%d", &n);
  int i, j, k;
  int n0 = n;
  n = 0;
  for (i = 0; i < n0; i++) {
    scanf("%lld", &a[n]);
    if (a[n] > 0) n++;
    if (n > 120) {
      printf("3\n");
      return 0;
    }
  }
  int ans = 1000;
  for (int r = 0; r < n; r++) {
    for (i = 0; i < n; i++)
      for (j = 0; j < n; j++) {
        f[i][j] = 10000;
        if (i != j && i != r && j != r) {
          if (a[i] & a[j]) {
            f[i][j] = 1;
          }
        }
      }
    for (k = 0; k < n; k++) {
      for (i = 0; i < n; i++) {
        if (f[k][i] == 10000) continue;
        for (j = 0; j < n; j++) {
          if (f[i][k] + f[k][j] < f[i][j]) f[i][j] = f[i][k] + f[k][j];
        }
      }
    }
    for (i = 0; i < n; i++)
      if (a[r] & a[i]) {
        for (j = 0; j < n; j++)
          if (i != j) {
            if (a[r] & a[j]) {
              if (ans > f[i][j] + 2) {
                ans = f[i][j] + 2;
              }
            }
          }
      }
  }
  printf("%d\n", ans >= 1000 ? -1 : ans);
  return 0;
}
