#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
vector<int> gr[200];
int g[200][200];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  long long aux;
  v.push_back(0);
  for (int i = 1; i <= n; i++) {
    cin >> aux;
    if (aux) v.push_back(aux);
  }
  if (v.size() > 121) {
    cout << "3\n";
    return 0;
  }
  n = v.size() - 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < i; j++) {
      if ((v[i] & v[j]) != 0) {
        gr[i].push_back(j);
        gr[j].push_back(i);
        g[i][j] = g[j][i] = 1;
      }
    }
  }
  int ans = 1e9;
  for (int i = 1; i <= n; i++) {
    vector<int> d(n + 1, 1e9);
    vector<int> p(n + 1, -1);
    d[i] = 0;
    queue<int> q;
    q.push(i);
    while (!q.empty()) {
      auto &u = q.front();
      q.pop();
      for (auto &o : gr[u]) {
        if (d[u] + 1 < d[o]) {
          d[o] = d[u] + 1;
          p[o] = u;
          q.push(o);
        } else if (o != p[u]) {
          ans = min(ans, d[o] + d[u] + 1);
        }
      }
    }
  }
  if (ans > 1e8) {
    ans = -1;
  }
  cout << ans << "\n";
  return 0;
}
