#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long> v[100009];
  vector<pair<long long, long long> > nums(n);
  for (long long i = (0); i < (n); i++) {
    long long aux;
    cin >> aux;
    nums[i] = make_pair(i, aux);
  }
  set<long long> verif[100009];
  long long aux = 1;
  for (long long i = (0); i < (60); i++) {
    vector<long long> pos;
    int cant = 0;
    for (long long j = (0); j < (n); j++) {
      if ((nums[j].second & aux)) {
        cant++;
        pos.push_back(nums[j].first);
      }
    }
    aux *= 2;
    if (cant >= 3) {
      cout << 3;
      return 0;
    }
    if (int(pos.size()) == 2) {
      if (!verif[pos[0]].count(pos[1])) {
        verif[pos[0]].insert(pos[1]);
        v[pos[0]].push_back(pos[1]);
      }
      if (!verif[pos[1]].count(pos[0])) {
        verif[pos[1]].insert(pos[0]);
        v[pos[1]].push_back(pos[0]);
      }
    }
  }
  int ans = n + 1;
  int d[100009], p[100009];
  for (long long i = (0); i < (n); i++) {
    queue<int> q;
    set<int> vis;
    q.push(i);
    d[i] = 0;
    p[i] = -1;
    bool term = false;
    while (!q.empty()) {
      int w = q.front();
      vis.insert(w);
      q.pop();
      for (int u : v[w]) {
        if (p[w] == u) continue;
        if (vis.count(u)) {
          ans = min(ans, d[w] + d[u] + 1);
          term = true;
          break;
        } else {
          q.push(u);
          p[u] = w;
          d[u] = d[w] + 1;
        }
      }
      if (term) break;
    }
  }
  if (ans != n + 1) {
    cout << ans;
  } else
    cout << -1;
  return 0;
}
