#include <bits/stdc++.h>
using namespace std;
vector<int> cnt[61], adj[100001];
vector<pair<int, int> > edge;
int d[100001];
int main() {
  long long x;
  int n, u, v;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &x);
    for (int j = 0; j < 61; j++) {
      if (x & 1ll << j) cnt[j].push_back(i);
    }
  }
  for (int i = 0; i < 61; i++) {
    if (cnt[i].size() > 2) {
      printf("3\n");
      return 0;
    } else if (cnt[i].size() == 2) {
      u = cnt[i][0];
      v = cnt[i][1];
      adj[u].push_back(v);
      adj[v].push_back(u);
      edge.push_back({u, v});
    }
  }
  int ans = 955360811;
  for (int i = 0; i < edge.size(); i++) {
    u = edge[i].first;
    memset(d, 0, sizeof d);
    d[u] = 1;
    queue<int> q;
    q.push(u);
    while (!q.empty()) {
      u = q.front();
      q.pop();
      for (int j = 0; j < adj[u].size(); j++) {
        x = adj[u][j];
        if (u == edge[i].first && x == edge[i].second) continue;
        if (d[x] == 0) {
          d[x] = d[u] + 1;
          q.push(x);
        }
      }
    }
    if (d[edge[i].second] == 0) continue;
    ans = min(ans, d[edge[i].second]);
  }
  if (ans == 955360811) ans = -1;
  printf("%d\n", ans);
  return 0;
}
