#include <bits/stdc++.h>
long long read() {
  long long ret = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar();
  return ret;
}
int min(int a, int b) { return a < b ? a : b; }
const int MAXN = 205, INF = 999999;
int N, dis[MAXN][MAXN], G[MAXN][MAXN];
long long a[100005];
int ans = INF, NN;
int main() {
  NN = read();
  int cnt;
  int i, j, k;
  long long x;
  for (i = 1; i <= NN; ++i) {
    x = read();
    if (x) a[++N] = x;
  }
  if (N >= 200) {
    puts("3");
    return 0;
  }
  for (i = 1; i <= N; ++i)
    for (j = 1; j <= N; ++j) dis[i][j] = INF;
  for (i = 1; i <= N; ++i)
    for (j = 1; j < i; ++j)
      if (a[i] & a[j]) dis[i][j] = dis[j][i] = 1;
  for (i = 1; i <= N; ++i)
    for (j = 1; j <= N; ++j) G[i][j] = dis[i][j];
  for (k = 1; k <= N; ++k) {
    for (i = 1; i < k; ++i)
      for (j = 1; j < i; ++j) ans = min(ans, dis[i][j] + G[i][k] + G[k][j]);
    for (i = 1; i <= N; ++i)
      for (j = 1; j <= N; ++j)
        dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
  }
  if (ans == INF)
    puts("-1");
  else
    printf("%d", ans);
  return 0;
}
