#include <bits/stdc++.h>
using namespace std;
long long n;
long long a[100010] = {};
inline long long read() {
  long long s = 0, w = 1;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '0') c = getchar();
  if (c == '-') w = -1, c = getchar();
  while (c <= '9' && c >= '0') s = (s << 3) + (s << 1) + c - '0', c = getchar();
  return s * w;
}
long long inzero = 0, len = 0;
struct rode {
  long long y, next;
} e[100010 << 1] = {};
long long fl[100010] = {}, cnt = 0;
inline void inc(long long x, long long y) {
  e[++cnt].y = y;
  e[cnt].next = fl[x];
  fl[x] = cnt;
}
long long f[200][200] = {};
bool vis[100010] = {};
bool loop[100010] = {};
long long minn = 1e9;
long long dfn[100010] = {}, low[100010] = {};
long long b[200][200] = {};
signed main() {
  n = read();
  for (long long i = 1; i <= n; ++i) {
    long long x = read();
    if (x == 0) continue;
    ++inzero;
    if (inzero > 128) {
      puts("3");
      return 0;
    }
    a[++len] = x;
  }
  memset(b, 0x3f, sizeof b);
  memset(f, 0x3f, sizeof f);
  for (long long i = 1; i <= len; ++i)
    for (long long j = 1; j < i; ++j)
      if ((a[i] & a[j]) > 0) b[i][j] = b[j][i] = 1, f[i][j] = f[j][i] = 1;
  long long minn = 0x3f3f3f3f;
  for (long long k = 1; k <= len; ++k) {
    for (long long i = 1; i < k; ++i)
      for (long long j = 1; j < i; ++j)
        if (b[i][k] < len && b[k][j] < len && f[i][j] < len)
          minn = min(minn, f[i][j] + b[i][k] + b[k][j]);
    for (long long i = 1; i <= len; ++i)
      for (long long j = 1; j <= len; ++j)
        f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
  }
  printf("%lld\n", minn >= 0x3f3f3f3f || minn < 1 ? -1 : minn);
  return 0;
}
