#include <bits/stdc++.h>
using namespace std;
const long long int INF = LONG_LONG_MAX >> 1;
const long long int NINF = LONG_LONG_MIN / 2;
const long long int N = 100009;
long long int d[N];
bool vis[N];
set<long long int> adj[N];
long long int dist(long long int u, long long int v) {
  bool found = false;
  queue<long long int> q;
  q.push(u);
  vis[u] = true;
  set<long long int> s;
  s.insert(u);
  d[u] = 0;
  while (!q.empty()) {
    long long int y = q.front();
    q.pop();
    for (long long int x : adj[y]) {
      if (!vis[x]) {
        vis[x] = true;
        q.push(x);
        d[x] = d[y] + 1;
        s.insert(x);
        if (x == v) {
          found = true;
          break;
        }
      }
    }
  }
  for (long long int x : s) vis[x] = false;
  if (found)
    return d[v];
  else
    return INF;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int n;
  cin >> n;
  long long int a[n];
  for (long long int& x : a) cin >> x;
  long long int len = 1;
  set<long long int> used;
  for (long long int i = 0; i < 64; i++) {
    vector<long long int> cluster;
    for (long long int j = 0; j < n; j++) {
      if ((a[j] & (1ll << i)) != 0) {
        cluster.push_back(j);
      }
    }
    if (cluster.size() >= 3) {
      cout << 3 << endl;
      return 0;
    }
    if (cluster.size() == 2) {
      adj[cluster[0]].insert(cluster[1]);
      adj[cluster[1]].insert(cluster[0]);
    }
    len++;
  }
  long long int ans = INF;
  vector<pair<long long int, long long int> > edges;
  for (long long int i = 0; i < n; i++) {
    for (long long int x : adj[i]) edges.push_back({x, i});
  }
  for (pair<long long int, long long int> p : edges) {
    long long int u = p.first;
    long long int v = p.second;
    adj[u].erase(v);
    adj[v].erase(u);
    ans = min(ans, dist(u, v) + 1);
    adj[u].insert(v);
    adj[v].insert(u);
  }
  if (ans != INF && ans >= 3) {
    cout << ans << endl;
  } else
    cout << -1 << endl;
}
