#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
vector<long long> g[100010];
template <typename T>
void make_set(vector<T> &v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
}
map<long long, long long> bfs(long long src) {
  map<long long, long long> dist;
  queue<long long> q;
  q.push(src);
  dist[src] = 0;
  while (!q.empty()) {
    long long node = q.front();
    q.pop();
    for (auto x : g[node])
      if (!dist.count(x)) {
        dist[x] = 1 + dist[node];
        q.push(x);
      }
  }
  return dist;
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (long long i = 0; i < n; ++i) {
    cin >> v[i];
  }
  vector<pair<long long, long long>> edges;
  for (long long i = 61; i >= 0; i--) {
    long long ct = 0;
    vector<long long> val;
    for (long long j = 0; j < n; j++) {
      long long x = v[j];
      if ((x >> i) & 1) ct++, val.push_back(j);
    }
    if (ct > 2) {
      cout << 3 << '\n';
      return;
    }
    if (val.size() == 2) {
      g[val.front()].push_back(val.back());
      g[val.back()].push_back(val.front());
      edges.push_back(minmax(val.back(), val.front()));
    }
  }
  make_set(edges);
  for (long long i = 0; i < n; i++) make_set(g[i]);
  long long ans = LLONG_MAX;
  for (auto x : edges) {
    g[x.first].erase(find(g[x.first].begin(), g[x.first].end(), x.second));
    g[x.second].erase(find(g[x.second].begin(), g[x.second].end(), x.first));
    map<long long, long long> mp = bfs(x.first);
    if (mp.count(x.second)) ans = min(ans, 1 + mp[x.second]);
    g[x.first].push_back(x.second);
    g[x.second].push_back(x.first);
  }
  if (ans == LLONG_MAX) ans = -1;
  cout << ans << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long t = 1;
  while (t--) solve();
  return 0;
}
