#include <bits/stdc++.h>
using namespace std;
const int N = 322;
const int inf = 2e9;
int n;
vector<long long> a;
int dist[N];
bool vis[N], connect[N][N];
int ans = inf;
vector<int> g[N];
void bfs(int from, int to) {
  queue<int> q;
  memset(vis, false, sizeof vis);
  for (int i = 0; i < n; i++) dist[i] = inf;
  q.push(from);
  dist[from] = 0;
  vis[from] = true;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int v : g[u])
      if (!vis[v]) {
        q.push(v);
        vis[v] = true;
        dist[v] = dist[u] + 1;
      }
  }
  ans = min(ans, dist[to] + 1);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    long long x;
    scanf("%lld", &x);
    if (x > 0) a.push_back(x);
  }
  n = (int)a.size();
  if (n > 322) return puts("3"), 0;
  vector<pair<int, int>> edges;
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      if (a[i] & a[j]) {
        g[i].push_back(j);
        g[j].push_back(i);
        edges.emplace_back(i, j);
      }
  for (auto p : edges) {
    int from = p.first;
    int to = p.second;
    g[from].erase(find(g[from].begin(), g[from].end(), to));
    g[to].erase(find(g[to].begin(), g[to].end(), from));
    bfs(from, to);
    g[from].push_back(to);
    g[to].push_back(from);
  }
  printf("%d\n", (ans == inf ? -1 : ans));
  return 0;
}
