#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <typename T>
using lim = numeric_limits<T>;
template <typename T>
istream& operator>>(istream& is, vector<T>& a) {
  for (T& x : a) {
    is >> x;
  }
  return is;
}
template <bool Directed, typename TEdge, bool Index>
struct graph {
  using EType = TEdge;
  vector<TEdge> edges;
  vector<vector<int>> adj;
  graph(int n) : adj(n + Index) {}
  graph(int n, int m) : graph(n) { edges.reserve(m << not Directed); }
  TEdge& operator()(int i) { return edges[i]; }
  vector<int>& operator[](int u) { return adj[u]; }
  int size() { return adj.size() - Index; }
  void add_edge(const TEdge& e) {
    adj[e.u].push_back(edges.size());
    edges.push_back(e);
    if (not Directed) {
      adj[e.v].push_back(edges.size());
      edges.push_back(e.reverse());
    }
  }
};
struct edge {
  int u, v;
  edge reverse() const { return {v, u}; }
  friend ostream& operator<<(ostream& os, const edge& e) {
    return os << "(" << e.u << ", " << e.v << ")";
  }
};
template <bool Directed, typename TEdge, bool Index>
vector<int> construct_path(const graph<Directed, TEdge, Index>& g,
                           const vector<int>& parent, int t) {
  vector<int> ans = {t};
  while (parent[ans.back()] != -1) {
    ans.push_back(parent[ans.back()]);
  }
  reverse(ans.begin(), ans.end());
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<ll> a(n);
  cin >> a;
  vector<vector<int>> nodes_at(63);
  size_t max_size = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 63; j++) {
      if (a[i] & (1ll << j)) {
        nodes_at[j].push_back(i);
        max_size = max(max_size, nodes_at[j].size());
      }
    }
  }
  if (max_size >= 3) {
    cout << 3 << endl;
  } else {
    graph<0, edge, 0> g(n);
    for (auto& v : nodes_at) {
      if (v.size() == 2) {
        g.add_edge({v[0], v[1]});
      }
    }
    int ans = lim<int>::max();
    vector<int> d(g.adj.size(), -1), p(g.adj.size());
    auto lca = [&](int u, int v) {
      while (d[u] > d[v]) u = p[u];
      while (d[v] > d[u]) v = p[v];
      while (u != v) u = p[u], v = p[v];
      return u;
    };
    auto dist = [&](int u, int v) { return d[u] + d[v] - 2 * d[lca(u, v)]; };
    for (int s = 0; s < n; s++) {
      if (d[s] == -1) {
        d[s] = 0, p[s] = -1;
        queue<int> q({s});
        while (not q.empty()) {
          int u = q.front();
          q.pop();
          for (int i : g[u]) {
            if (d[g(i).v] == -1) {
              d[g(i).v] = d[g(i).u] + 1, p[g(i).v] = u;
              q.push(g(i).v);
            } else if (dist(u, g(i).v) > 1) {
              ans = min(ans, dist(u, g(i).v) + 1);
            }
          }
        }
      }
    }
    cout << (ans == lim<int>::max() ? -1 : ans) << endl;
  }
  return 0;
}
