#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const int MAXN = 130;
int n, cnt, res, mp[MAXN][MAXN], g[MAXN][MAXN];
long long a[int(1e5 + 7)], tmp;
void floyd() {
  res = INF;
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i < k; i++)
      for (int j = i + 1; j < k; j++)
        res = min(res, g[i][j] + mp[i][k] + mp[k][j]);
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        g[i][j] = g[j][i] = min(g[i][j], g[i][k] + g[k][j]);
  }
}
int main() {
  cnt = 1;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &tmp);
    if (tmp > 0) a[cnt++] = tmp;
  }
  if (cnt >= 130)
    printf("3\n");
  else {
    n = cnt;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if ((a[i] & a[j]) && i != j)
          mp[i][j] = g[i][j] = 1;
        else
          mp[i][j] = g[i][j] = INF;
      }
    }
    floyd();
    if (res > n)
      printf("-1\n");
    else
      printf("%d\n", res);
  }
  return 0;
}
