#include <bits/stdc++.h>
using namespace std;
const long long maxN = 1000013;
long long n;
long long a[maxN];
long long color[maxN];
vector<long long> vec[maxN];
long long mabs(long long a) {
  if (a < 0) return -a;
  return a;
}
long long dfs(long long v, long long pr, long long out) {
  for (long long i = 0; i < vec[v].size(); ++i) {
    long long u = vec[v][i];
    if (u == pr) {
      continue;
    }
    if (color[u] != 0) {
      out = min(out, mabs(color[u] - color[v]) + 1);
      continue;
    }
    color[u] = color[v] + 1;
    long long out_new = dfs(u, v, out);
    out = min(out, out_new);
    if (out == 3) {
      color[v] = 0;
      return out;
    }
  }
  color[v] = 0;
  return out;
}
int main() {
  cin >> n;
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
    vec[i] = vector<long long>();
  }
  for (long long i = 0; i < 63; ++i) {
    vector<long long> v;
    for (long long j = 0; j < n; ++j) {
      if ((a[j] & (1ll << i)) != 0) {
        v.push_back(j);
      }
    }
    if (v.size() >= 3) {
      cout << 3 << endl;
      return 0;
    }
    if (v.size() != 2) continue;
    vec[v[0]].push_back(v[1]);
    vec[v[1]].push_back(v[0]);
  }
  long long out = maxN;
  for (long long i = 0; i < n; ++i) {
    if (color[i] == 0) {
      color[i] = 1;
      out = min(out, dfs(i, i, maxN));
      if (out == 3) {
        break;
      }
      color[i] = 0;
    }
  }
  cout << ((out == maxN) ? -1 : out) << endl;
  return 0;
}
