#include <bits/stdc++.h>
using namespace std;
vector<long long> adj[200001];
vector<long long> adj1[64];
long long n;
long long parent[200001];
long long helper() {
  long long ans = INT_MAX;
  for (long long i = 1; i <= n; i++) {
    vector<long long> dist(n + 2, (long long)(1e9));
    vector<long long> par(n + 1, -1);
    dist[i] = 0;
    queue<long long> q;
    q.push(i);
    while (!q.empty()) {
      long long x = q.front();
      q.pop();
      for (long long child : adj[x]) {
        if (dist[child] == (long long)(1e9)) {
          dist[child] = 1 + dist[x];
          par[child] = x;
          q.push(child);
        } else if (par[x] != child and par[child] != x)
          ans = min(ans, dist[x] + dist[child] + 1);
      }
    }
  }
  if (ans == INT_MAX)
    return -1;
  else
    return ans;
}
void solve() {
  cin >> n;
  bool ok = 0;
  for (long long i = 1; i <= n; i++) {
    long long a;
    cin >> a;
    long long ind = 0;
    if (a == 0) {
      i--, n--;
      continue;
    }
    while (a > 0) {
      if (a & 1) {
        adj1[ind].push_back(i);
        if (adj1[ind].size() > 1) ok = 1;
        if (adj1[ind].size() >= 3) {
          cout << 3 << endl;
          exit(0);
        }
      }
      a /= 2;
      ind++;
    }
  }
  if (!ok) {
    cout << -1 << endl;
    return;
  }
  long long cal = 0;
  for (long long i = 0; i < 64; i++) {
    assert(adj1[i].size() < 3);
    if (adj1[i].size() == 2) {
      long long val1 = adj1[i][0];
      long long val2 = adj1[i][1];
      adj[val1].push_back(val2);
      adj[val2].push_back(val1);
      cal++;
    }
  }
  assert(cal < 64);
  cout << helper() << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  while (t--) solve();
  return 0;
}
