#include <bits/stdc++.h>
using namespace std;
const long long int N = 256;
long long int n, d[N], vis[N], pa[N];
vector<long long int> b[N];
set<long long int> g[N];
long long int bfs(long long int v) {
  long long int res = INT_MAX;
  memset(d, 0, sizeof(d));
  memset(pa, -1, sizeof(pa));
  memset(vis, 0, sizeof(vis));
  queue<long long int> q;
  vis[v] = 1;
  q.push(v);
  while (!q.empty()) {
    long long int curr = q.front();
    q.pop();
    for (long long int i : g[curr]) {
      if (i == pa[curr]) continue;
      if (vis[i]) {
        res = min(res, d[i] + d[curr] + 1);
      } else {
        pa[i] = curr;
        d[i] = d[curr] + 1;
        vis[i] = 1;
        q.push(i);
      }
    }
  }
  return res;
}
void solve() {
  long long int n;
  cin >> n;
  for (long long int i = 0; i < n; i++) {
    long long int a;
    cin >> a;
    for (long long int j = 0; j < 64; j++)
      if (a & ((long long int)1 << j)) b[j].push_back(i);
  }
  for (long long int i = 0; i < 64; i++) {
    if (b[i].size() > 2) {
      cout << 3 << endl;
      return;
    }
  }
  map<long long int, long long int> m;
  long long int qid = 0;
  for (long long int i = 0; i < 64; i++) {
    if (b[i].size() == 2) {
      long long int x = b[i][0], y = b[i][1];
      if (!m.count(x)) m[x] = qid++;
      if (!m.count(y)) m[y] = qid++;
      long long int l = m[x], r = m[y];
      g[l].insert(r);
      g[r].insert(l);
    }
  }
  long long int res = INT_MAX;
  for (long long int i = 0; i < m.size(); i++) {
    res = min(res, bfs(i));
  }
  if (res == INT_MAX)
    cout << -1 << endl;
  else
    cout << res << endl;
}
int32_t main() {
  ios_base ::sync_with_stdio(false), cin.tie(NULL);
  solve();
  return 0;
}
