#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100010];
int n, dist[100010], atual;
void bfs(int no) {
  for (int i = 1; i <= n; i++) dist[i] = 1e9;
  dist[no] = 0;
  queue<int> fila;
  fila.push(no);
  while (!fila.empty()) {
    int topo = fila.front();
    fila.pop();
    for (int filho : adj[topo]) {
      if (filho == atual && topo == no) continue;
      if (dist[filho] > dist[topo] + 1) {
        dist[filho] = dist[topo] + 1;
        fila.push(filho);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  bool arr[100010][65];
  memset(arr, false, sizeof arr);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> t;
    int cont = 0;
    while (t) {
      if (t & 1) arr[i][cont] = true;
      t = (t >> 1);
      cont++;
    }
  }
  vector<pair<long long, long long> > pares;
  for (int j = 0; j <= 64; j++) {
    bool dois = false;
    int temp = -1;
    for (int i = 1; i <= n; i++) {
      if (arr[i][j]) {
        if (temp == -1)
          temp = i;
        else {
          if (dois) {
            cout << 3 << endl;
            return 0;
          }
          adj[i].push_back(temp);
          adj[temp].push_back(i);
          dois = true;
          pares.push_back(make_pair(i, temp));
        }
      }
    }
  }
  int resp = 1e9;
  for (pair<long long, long long> parr : pares) {
    atual = parr.second;
    bfs(parr.first);
    resp = min(resp, dist[parr.second]);
  }
  if (resp == 1e9)
    cout << "-1\n";
  else
    cout << resp + 1 << endl;
}
