#include <bits/stdc++.h>
using namespace std;
bool adj[200][200];
int bfs(int source, int dest) {
  bool vis[200];
  for (int i = 0; i < 200; i++) vis[i] = 0;
  queue<pair<int, int> > qe;
  qe.push({source, 0});
  while (!qe.empty()) {
    int node = qe.front().first;
    int d = qe.front().second;
    qe.pop();
    if (node == dest) return d;
    vis[node] = 1;
    for (int i = 0; i < 200; i++) {
      if (adj[node][i] and !vis[i]) qe.push({i, d + 1});
    }
  }
  return INT_MAX;
}
int main() {
  int n;
  cin >> n;
  vector<long long> arr;
  while (n--) {
    long long x;
    cin >> x;
    if (x != 0) arr.push_back(x);
  }
  n = arr.size();
  if (n > 128) {
    cout << 3 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (arr[i] & arr[j]) adj[i][j] = 1;
    }
  }
  int min_cycle = INT_MAX;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (adj[i][j]) {
        adj[i][j] = 0;
        adj[j][i] = 0;
        int m = bfs(i, j);
        min_cycle = min(m, min_cycle);
        adj[i][j] = 1;
        adj[j][i] = 1;
      }
    }
  }
  if (min_cycle > 10000000)
    cout << -1 << endl;
  else
    cout << min_cycle + 1 << endl;
}
