#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
vector<ll> a;
set<int> G[((int)1e5 + 5)];
set<pair<int, int>> Edge;
vector<int> bit[128];
int dist[((int)1e5 + 5)];
int bfs(int s, int e);
int main() {
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    int j = 0;
    while ((a[i] >> j) > 0) {
      if ((a[i] >> j) & 1) bit[j].emplace_back(i);
      j++;
    }
  }
  for (int i = 0; i < 128; i++) {
    if (bit[i].size() >= 3) {
      cout << "3\n";
      return 0;
    } else if (bit[i].size() == 2) {
      G[bit[i][0]].emplace(bit[i][1]);
      G[bit[i][1]].emplace(bit[i][0]);
      Edge.emplace(bit[i][0], bit[i][1]);
    }
  }
  int ans = 1e9;
  for (auto& e : Edge) {
    ans = min(ans, bfs(e.first, e.second) + 1);
  }
  cout << (ans == 1e9 ? -1 : ans) << '\n';
  return 0;
}
int bfs(int s, int e) {
  fill(dist, dist + ((int)1e5 + 5), -1);
  queue<int> q;
  q.emplace(s);
  dist[s] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto& v : G[u]) {
      if (dist[v] != -1) continue;
      if ((u == s && v == e) || (v == s && u == e)) continue;
      q.emplace(v);
      dist[v] = dist[u] + 1;
    }
  }
  return (dist[e] == -1) ? 1e9 : dist[e];
}
