#include <bits/stdc++.h>
using namespace std;
long long a[100005];
long long d[800][800], g[800][800];
int w[100];
vector<long long> v;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    long long x = a[i];
    int cnt = 0;
    while (x) {
      if (x % 2) w[cnt]++;
      cnt++;
      x /= 2;
    }
  }
  for (int i = 0; i < 70; i++) {
    if (w[i] >= 3) {
      printf("3\n");
      return 0;
    }
  }
  v.push_back(0);
  for (int i = 1; i <= n; i++) {
    if (a[i]) v.push_back(a[i]);
  }
  n = v.size() - 1;
  if (n > 300) {
    printf("3\n");
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) d[i][j] = g[i][j] = 0x3f3f3f3f;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (v[i] & v[j]) d[i][j] = 1, d[j][i] = 1, g[i][j] = 1, g[j][i] = 1;
    }
  }
  long long ans = 0x3f3f3f3f;
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i < k; i++) {
      for (int j = i + 1; j < k; j++)
        ans = min(ans, d[i][j] + g[i][k] + g[k][j]);
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }
  }
  if (ans == 0x3f3f3f3f) ans = -1;
  printf("%lld\n", ans);
  return 0;
}
