#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const long long INF = 0x3f3f3f3f;
long long a[maxn];
int n;
long long dis[150][150], D[150][150];
long long floyd() {
  for (auto i = 1; i <= n; i++)
    for (auto j = 1; j <= n; j++) dis[i][j] = D[i][j];
  long long ans = INF;
  for (auto k = 1; k <= n; k++) {
    for (auto i = 1; i < k; i++)
      for (auto j = 1; j < i; j++)
        ans = min(ans, D[i][j] + dis[i][k] + dis[k][j]);
    for (auto i = 1; i <= n; i++)
      for (auto j = 1; j <= n; j++)
        D[i][j] = D[j][i] = min(D[i][j], D[i][k] + D[k][j]);
  }
  return ans == INF ? -1 : ans;
}
int main() {
  long long x;
  scanf("%d", &n);
  int k = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &x);
    if (x) a[++k] = x;
  }
  if (k >= 130) {
    puts("3");
    return 0;
  }
  n = k;
  for (int i = 0; i <= 148; i++) fill(D[i], D[i] + 148, INF);
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++)
      if (a[i] & a[j]) D[i][j] = D[j][i] = 1;
  printf("%lld\n", floyd());
  return 0;
}
