#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j;
  long long x;
  vector<int> c[64], a[100000];
  scanf("%d", &n);
  for (i = 0; i < n; ++i) {
    scanf("%lld", &x);
    for (j = 0; (1LL << j) <= x; ++j)
      if ((1LL << j) & x) c[j].push_back(i), a[i].push_back(j);
  }
  for (i = 0; i < 64; ++i) {
    if (c[i].size() >= 3) printf("%d\n", 3), exit(0);
  }
  int ans = 0x3f3f3f3f;
  for (i = 0; i < 64; ++i)
    if (c[i].size() >= 2) {
      static int d[100000];
      queue<int> b;
      if (c[i][1] < c[i][0]) swap(c[i][0], c[i][1]);
      b.push(c[i][0]);
      memset(d, 0x3f, n * sizeof(int));
      d[c[i][0]] = 0;
      while (!b.empty()) {
        int x = b.front();
        b.pop();
        if (x == c[i][1]) break;
        for (int j : a[x])
          for (int k : c[j]) {
            if (x != k && d[k] > d[x] + 1 &&
                make_pair(min(x, k), max(x, k)) != make_pair(c[i][0], c[i][1]))
              d[k] = d[x] + 1, b.push(k);
          }
      }
      ans = min(ans, d[c[i][1]] + 1);
    }
  printf("%d\n", ans == 0x3f3f3f3f ? -1 : ans);
  return 0;
}
