#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const double eps = 1e-6;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const int maxn = 2e5 + 100;
long long a[maxn];
int mp[300][300], dis[300][300];
void solve() {
  int n, c = 0;
  scanf("%d", &n);
  for (int i = 1; (i) <= (n); i++) {
    long long mark;
    scanf("%lld", &mark);
    if (mark) a[++c] = mark;
  }
  if (c >= 200) {
    printf("3\n");
    return;
  }
  memset(mp, inf, sizeof(mp));
  memset(dis, inf, sizeof(dis));
  for (int i = 1; (i) <= (c); i++)
    for (int j = 1; (j) <= (c); j++)
      if (i != j && (a[i] & a[j])) mp[i][j] = dis[i][j] = 1;
  int MinCost = inf;
  for (int k = 1; k <= c; k++) {
    for (int i = 1; i < k; i++)
      for (int j = i + 1; j < k; j++)
        MinCost = (int)min(1LL * MinCost,
                           1LL * dis[i][j] + 1LL * mp[i][k] + 1LL * mp[k][j]);
    for (int i = 1; i <= c; i++)
      for (int j = 1; j <= c; j++)
        dis[i][j] =
            (int)min(1LL * dis[i][j], 1LL * dis[i][k] + 1LL * dis[k][j]);
  }
  printf("%d\n", MinCost == inf ? -1 : MinCost);
}
int main() {
  solve();
  return 0;
}
