#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int INF = 0x3f3f3f3f;
long long ksm(long long a, long long b) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const int N = 1e5 + 10;
int n;
long long ans = INF;
long long a[N];
int g[130][130], d[130][130];
void floyd() {
  memcpy(d, g, sizeof g);
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= k - 1; i++) {
      for (int j = i + 1; j <= k - 1; j++) {
        if (ans > (long long)d[i][j] + g[k][i] + g[j][k]) {
          ans = d[i][j] + g[k][i] + g[j][k];
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}
int main() {
  memset(g, 0x3f, sizeof(g));
  for (int i = 1; i <= n; i++) g[i][i] = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    if (a[i] == 0) {
      n--, i--;
    }
  }
  if (n > 128) {
    printf("3");
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (j != i && (a[i] & a[j])) {
        g[i][j] = g[j][i] = 1;
      }
    }
  }
  floyd();
  printf("%d\n", ans == INF ? -1 : ans);
  return 0;
}
