#include <bits/stdc++.h>
const int N = 200005;
int n, g[200][200], f[200][200], ans = 1 << 29;
long long a[N];
using namespace std;
void force() {
  int i, j, k;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++)
      if (i != j) f[i][j] = 1000;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++)
      if (i != j && (a[i] & a[j])) f[i][j] = g[i][j] = 1;
  for (k = 1; k <= n; k++) {
    for (i = 1; i < k; i++)
      for (j = i + 1; j < k; j++)
        if (g[i][k] && g[k][j] && f[i][j] < 1000) ans = min(ans, f[i][j] + 2);
    for (i = 1; i <= n; i++)
      for (j = 1; j <= n; j++) f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
  }
  if (ans == (1 << 29)) ans = -1;
  cout << ans;
}
int main() {
  cin >> n;
  int i, j, m = 0;
  long long v;
  for (i = 1; i <= n; i++) {
    scanf("%lld", &v);
    if (v) a[++m] = v;
  }
  n = m;
  if (n <= 130) {
    force();
    return 0;
  }
  puts("3");
  return 0;
}
