#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
template <typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
};
template <typename T>
using Edges = vector<edge<T>>;
template <typename T>
using WeightedGraph = vector<Edges<T>>;
template <typename T>
vector<T> dijkstra(WeightedGraph<T> &g, int s, int t) {
  const auto INF = numeric_limits<T>::max();
  vector<T> dist(g.size(), INF);
  priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while (que.empty() != true) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if (dist[idx] < cost) continue;
    for (auto &e : g[idx]) {
      if ((idx == s && e.to == t) || (idx == t && e.to == s)) continue;
      auto next_cost = cost + e.cost;
      if (dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      que.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}
int func(vector<ll> a) {
  int N = a.size();
  WeightedGraph<int> G(N);
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (a[i] & a[j]) {
        G[i].emplace_back(j, 1);
        G[j].emplace_back(i, 1);
      }
    }
  }
  int res = inf;
  for (int i = 0; i < N; i++) {
    for (auto &v : G[i]) {
      auto dist = dijkstra(G, i, v.to);
      if (dist[v.to] < inf) res = min(res, dist[v.to] + 1);
    }
  }
  return res;
}
int N;
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> N;
  vector<ll> a, bit(65);
  for (int i = 0; i < N; i++) {
    ll p;
    cin >> p;
    if (p != 0LL)
      a.emplace_back(p);
    else
      continue;
    for (ll b = 0; b < 60; b++) {
      if ((1LL << b) & p) bit[b]++;
    }
  }
  if (*max_element(bit.begin(), bit.end()) > 2) {
    cout << 3 << endl;
    return 0;
  }
  int ans = func(a);
  if (ans == inf) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}
