#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-6;
const long long mod = 998244353;
const int inf = 0x7fffffff;
const int maxn = 100005;
inline long long qpow(long long x, long long y, long long Mod) {
  long long ans = 1, base = x % Mod;
  while (y) {
    if (y & 1) ans = (ans * base) % Mod;
    base = (base * base) % Mod;
    y >>= 1;
  }
  return ans;
}
inline long long gcd(long long a, long long b) {
  while (b) {
    long long c = b;
    b = a % b;
    a = c;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
template <class T>
inline void read(T &x) {
  x = 0;
  int f = 0;
  char ch = getchar();
  while (ch < 48 || ch > 57) {
    f |= (ch == '-');
    ch = getchar();
  }
  while (ch >= 48 && ch <= 57) {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  x = f ? -x : x;
  return;
}
template <class T>
inline void write(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
long long n, a[maxn], mm[150][150], dp[150][150], ans = inf;
int main() {
  long long x, cnt = 0;
  read(n);
  for (register int i = (1); i <= (n); ++i) {
    read(x);
    if (x != 0) a[++cnt] = x;
  }
  if (cnt > 128) {
    printf("3\n");
    return 0;
  }
  for (register int i = (1); i <= (cnt); ++i) {
    for (register int j = (1); j <= (cnt); ++j) {
      dp[i][j] = mm[i][j] = inf;
      if (i != j && (a[i] & a[j]) != 0) {
        dp[i][j] = mm[i][j] = 1;
      }
    }
  }
  for (int k = 1; k <= cnt; k++) {
    for (int i = 1; i < k; i++) {
      for (int j = i + 1; j < k; j++) {
        ans = min(ans, dp[i][j] + mm[i][k] + mm[k][j]);
      }
    }
    for (int i = 1; i <= cnt; i++) {
      for (int j = 1; j <= cnt; j++) {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
      }
    }
  }
  if (ans >= inf)
    printf("-1\n");
  else
    printf("%lld\n", ans);
  return 0;
}
