#include <bits/stdc++.h>
using namespace std;
int n, ans = 1e9;
vector<vector<int> > cnt(65);
vector<set<int> > ed;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  ed.resize(n + 1);
  bool tw = false;
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    int d = 0;
    while (a && !(tw)) {
      if (a & 1) {
        for (int k : cnt[d]) {
          if (ed[k].find(i) == ed[k].end()) {
            ed[k].insert(i);
            ed[i].insert(k);
          }
        }
        cnt[d].push_back(i);
        if (cnt[d].size() > 2) tw = true;
      }
      a >>= 1, d++;
    }
  }
  if (tw) {
    cout << 3 << "\n";
    return 0;
  }
  for (int j = 0; j < 64; j++) {
    unordered_set<int> vis;
    if (cnt[j].size() == 2) {
      queue<pair<int, int> > q;
      for (int k : ed[cnt[j][0]])
        if (k != cnt[j][1]) q.push(make_pair(k, 1));
      vis.insert(cnt[j][0]);
      while (!q.empty()) {
        pair<int, int> cur = q.front();
        q.pop();
        if (vis.find(cur.first) != vis.end()) continue;
        vis.insert(cur.first);
        if (cur.first == cnt[j][1]) {
          ans = min(ans, cur.second);
          break;
        }
        for (int k : ed[cur.first]) q.push(make_pair(k, cur.second + 1));
      }
    }
  }
  if (ans == 1e9)
    cout << -1 << "\n";
  else
    cout << ans + 1 << "\n";
}
