#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, ret = 1 << 25;
long long a[N];
int fre[N], dist[N];
vector<int> ad[N];
vector<pair<int, int>> ed;
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < 60; ++i) {
    vector<int> b;
    for (int j = 0; j < n; ++j) {
      if (a[j] >> i & 1) b.push_back(j);
    }
    if (b.size() > 2) return cout << 3, 0;
    if (b.size() > 1) ed.push_back({b[0], b[1]});
  }
  sort(ed.begin(), ed.end());
  ed.erase(unique(ed.begin(), ed.end()), ed.end());
  for (int i = 0; i < (int)ed.size(); ++i) {
    ad[ed[i].first].push_back(i);
    ad[ed[i].second].push_back(i);
  }
  for (int i = 0; i < (int)ed.size(); ++i) {
    queue<int> q;
    q.push(ed[i].first);
    fre[ed[i].first] = i + 1;
    dist[ed[i].first] = 1;
    while (q.size()) {
      int u = q.front();
      q.pop();
      if (u == ed[i].second) {
        ret = min(ret, dist[u]);
        break;
      }
      for (int j : ad[u]) {
        if (j == i) continue;
        int v = u ^ ed[j].first ? ed[j].first : ed[j].second;
        if (fre[v] < i + 1) {
          q.push(v);
          fre[v] = i + 1;
          dist[v] = dist[u] + 1;
        }
      }
    }
  }
  cout << (ret == 1 << 25 ? -1 : ret);
}
