#include <bits/stdc++.h>
using namespace std;
const long long G = 3;
const long long M = 998244353;
const long long ff = 4e5 + 15;
const long long inf = 1e17 + 1;
const long long base = 2333;
const double eps = 1e-8;
inline long long read() {
  long long x;
  scanf("%lld", &x);
  return x;
}
long long n, a[ff], tp;
long long dis[129][129], e[129][129], ans = inf;
void init() {
  cin >> n;
  for (long long i = 1; i <= n; ++i) {
    long long x;
    scanf("%lld", &x);
    if (x != 0) a[++tp] = x;
  }
  n = tp;
  if (n > 128) {
    puts("3");
    return;
  }
  for (long long i = 1; i <= n; ++i)
    for (long long j = 1; j <= n; ++j)
      if (i != j) dis[i][j] = e[i][j] = inf;
  for (long long i = 1; i <= n; ++i)
    for (long long j = i + 1; j <= n; ++j)
      if ((a[i] & a[j]) != 0) dis[i][j] = dis[j][i] = e[i][j] = e[j][i] = 1;
  for (long long k = 1; k <= n; ++k) {
    for (long long i = 1; i <= k - 1; ++i)
      for (long long j = i + 1; j <= k - 1; ++j)
        ans = min(ans, dis[i][j] + e[i][k] + e[k][j]);
    for (long long i = 1; i <= n; ++i)
      for (long long j = 1; j <= n; ++j)
        dis[i][j] = dis[j][i] = min(dis[i][j], dis[i][k] + dis[k][j]);
  }
  if (ans == inf)
    cout << "-1\n";
  else
    cout << ans << "\n";
}
signed main() {
  long long Ts = 1;
  while (Ts--) init();
}
