#include <bits/stdc++.h>
using namespace std;
void did() { cerr << "-1\n"; }
const int N = 1e5;
int gr[200][200];
long long a[1 + N];
int dist[200];
int intorc[200];
map<int, int> mp;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int cnt = 0;
  for (int bit = 0; bit < 61; bit++) {
    long long this_nuts = 0;
    int nr = 0;
    vector<long long> good;
    for (int i = 1; i <= n; i++)
      if (a[i] & (1ll << bit)) nr++, good.push_back(i);
    if (nr > 2) {
      cout << 3 << "\n";
      return 0;
    }
    if (nr == 2) {
      if (mp[good[0]] == 0) mp[good[0]] = ++cnt;
      if (mp[good[1]] == 0) mp[good[1]] = ++cnt;
      gr[mp[good[0]]][mp[good[1]]] = 1;
      gr[mp[good[1]]][mp[good[0]]] = 1;
    }
  }
  int ans = -1;
  for (int i = 1; i <= cnt; i++) {
    queue<int> q;
    for (int j = 1; j <= cnt; j++) dist[j] = -1;
    q.push(i);
    dist[i] = 0;
    while (q.empty() == false) {
      int bit = q.front();
      q.pop();
      for (int vec = 1; vec <= cnt; vec++) {
        if (gr[bit][vec] == 0) continue;
        if (dist[vec] == -1) {
          dist[vec] = dist[bit] + 1;
          intorc[vec] = bit;
          q.push(vec);
        } else {
          int cyc = dist[bit] + dist[vec] + 1;
          if (intorc[bit] == vec) continue;
          if (ans == -1 || ans > cyc) ans = cyc;
        }
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
