#include <bits/stdc++.h>
using namespace std;
list<long long> adj[100005];
long long Dijkstra(long long src, long long des, long long n) {
  vector<long long> dist(n, 1e18);
  dist[src] = 0;
  queue<long long> q;
  q.push(src);
  while (!q.empty()) {
    long long u = q.front();
    q.pop();
    for (auto x : adj[u]) {
      if (dist[x] > dist[u] + 1) {
        dist[x] = dist[u] + 1;
        q.push(x);
      }
    }
  }
  return dist[des];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, i, j, x, cnt, y;
  cin >> n;
  long long a[n + 1];
  for (i = 1; i <= n; i++) cin >> a[i];
  vector<long long> v[61];
  long long flag = 0;
  for (i = 1; i <= n; i++) {
    if (a[i] == 0) continue;
    x = 1;
    cnt = 0;
    while (x <= a[i]) {
      if (x & a[i]) {
        v[cnt].push_back(i);
        if (v[cnt].size() > 2) {
          flag = 1;
          break;
        }
      }
      x *= 2;
      cnt++;
    }
    if (flag) {
      cout << 3;
      return 0;
    }
  }
  vector<pair<long long, long long> > e;
  map<pair<long long, long long>, long long> mp;
  for (i = 0; i <= 60; i++) {
    if (v[i].size() == 2) {
      if (mp[{v[i][0], v[i][1]}] == 0) {
        e.push_back({v[i][0], v[i][1]});
        mp[{v[i][0], v[i][1]}]++;
        mp[{v[i][1], v[i][0]}]++;
      }
    }
  }
  for (auto p : e) {
    adj[p.first].push_back(p.second);
    adj[p.second].push_back(p.first);
  }
  long long ans = 1e18;
  for (auto p : e) {
    x = p.first;
    y = p.second;
    adj[x].remove(y);
    adj[y].remove(x);
    long long temp = Dijkstra(x, y, n + 1);
    ans = min(ans, temp);
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  if (ans == 1e18)
    cout << "-1";
  else
    cout << ans + 1;
}
