#include <bits/stdc++.h>
using namespace std;
long long inline read() {
  long long num = 0, neg = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') neg = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    num = (num << 3) + (num << 1) + c - '0';
    c = getchar();
  }
  return num * neg;
}
const long long maxn = 100010;
long long n, A[maxn], a[maxn], dis[200][200], chushi[200][200], stk[maxn],
    ans = 2147483647 / 3, flg;
void floyd() {
  for (long long k = 1; k <= n; k++) {
    for (long long i = 1; i <= n; i++)
      for (long long j = 1; j <= n; j++) {
        if (i == j || j == k || i == k) continue;
        if (dis[i][j] + chushi[i][k] + chushi[k][j] < ans) {
          ans = dis[i][j] + chushi[i][k] + chushi[k][j];
          flg = 1;
        }
      }
    for (long long i = 1; i <= n; i++)
      for (long long j = 1; j <= n; j++) {
        if (i == j || j == k || i == k) continue;
        if (dis[i][k] + dis[k][j] < dis[i][j]) {
          dis[i][j] = dis[i][k] + dis[k][j];
        }
      }
  }
}
signed main() {
  n = read();
  long long cnt = 0;
  for (long long i = 1; i <= n; i++) A[i] = read();
  for (long long i = 1; i <= n; i++)
    if (A[i] != 0) a[++cnt] = A[i];
  n = cnt;
  cnt = 0;
  for (long long i = 1; i <= n; i++) {
    long long x = a[i];
    while (x) {
      cnt++;
      x -= x & (-x);
    }
  }
  if (cnt > 128) {
    cout << 3;
    return 0;
  }
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= n; j++)
      dis[i][j] = chushi[i][j] = 2147483647 / 3;
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= n; j++)
      if (a[i] & a[j]) dis[i][j] = chushi[i][j] = 1;
  floyd();
  if (flg)
    cout << ans;
  else
    cout << -1;
  return 0;
}
