#include <bits/stdc++.h>
using namespace std;
int lsone(int n) { return (n & -n); }
long long int pow1(long long int a, long long int b) {
  if (b == 0)
    return 1ll;
  else if (b == 1)
    return a;
  else {
    long long int x = pow1(a, b / 2);
    x *= x;
    x %= 1000000007;
    if (b % 2) {
      x *= a;
      x %= 1000000007;
    }
    return x;
  }
}
long long int n, arr[110000], numnotz, ans = 1e9, vis[200];
vector<long long int> a;
vector<vector<int> > graph(200);
queue<int> q;
void bfs(int index, int dest) {
  memset(vis, 0, sizeof(vis));
  q.push(index);
  vis[index] = 1;
  long long int minlen = 1e9;
  while (!q.empty()) {
    int node = q.front();
    q.pop();
    for (int neigh : graph[node]) {
      if (node == index and neigh == dest) continue;
      if (vis[neigh]) {
        continue;
      }
      q.push(neigh);
      vis[neigh] = 1 + vis[node];
    }
  }
  if (vis[dest] != 0) ans = min(ans, vis[dest]);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    if (arr[i] > 0) {
      numnotz++;
      a.push_back(arr[i]);
    }
  }
  if (numnotz > 128) {
    cout << 3 << "\n";
  } else {
    for (int i = 0; i < numnotz; i++) {
      for (int j = i + 1; j < numnotz; j++) {
        if (a[i] & a[j]) {
          graph[i].push_back(j);
          graph[j].push_back(i);
        }
      }
    }
    for (int i = 0; i < numnotz; i++) {
      for (int neigh : graph[i]) {
        bfs(i, neigh);
      }
    }
    if (ans == 1e9) ans = -1;
    cout << ans << "\n";
  }
  return 0;
}
