#include <bits/stdc++.h>
using namespace std;
long long int M = 100000000000000;
long long int M1 = 1000000007;
long long int fnddist(vector<vector<long long int> > &v, long long int x3,
                      long long int x4) {
  long long int x1, x2, i;
  vector<long long int> dist(v.size(), M);
  dist[x3] = 0;
  queue<long long int> q;
  q.push(x3);
  while (!q.empty()) {
    x1 = q.front();
    q.pop();
    for (i = 0; i < v[x1].size(); i++) {
      x2 = v[x1][i];
      if (x1 == x3 && x2 == x4) continue;
      if (x1 == x4 && x2 == x3) continue;
      if (dist[x2] > dist[x1] + 1) {
        q.push(x2);
        dist[x2] = dist[x1] + 1;
      }
    }
  }
  return dist[x4];
}
int main() {
  long long int n, i, j, x1, x2, x3, cnt, ans, dist;
  cin >> n;
  vector<long long int> v(n);
  for (i = 0; i < n; i++) cin >> v[i];
  vector<vector<long long int> > v1(n);
  vector<long long int> v2;
  vector<pair<long long int, long long int> > edge;
  for (i = 0; i < 63; i++) {
    v2.clear();
    cnt = 0;
    for (j = 0; j < n; j++) {
      x1 = v[j];
      x2 = (((long long)1 << i) & x1);
      if (x2 > 0) {
        cnt++;
        v2.push_back(j);
      }
    }
    if (cnt > 2) {
      cout << 3 << endl;
      return 0;
    } else if (cnt == 2) {
      x1 = v2[0];
      x2 = v2[1];
      v1[x1].push_back(x2);
      v1[x2].push_back(x1);
      edge.push_back(make_pair(x1, x2));
    }
  }
  ans = M;
  for (i = 0; i < edge.size(); i++) {
    x1 = edge[i].first;
    x2 = edge[i].second;
    dist = fnddist(v1, x1, x2);
    if (dist != M) ans = min(ans, dist + 1);
  }
  if (ans == M)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
