#include <bits/stdc++.h>
using namespace std;
vector<unsigned long long> node[1000000];
unsigned long long djikstra(unsigned long long s, unsigned long long d) {
  vector<bool> vis(1000000, false);
  vector<unsigned long long> dist(1000000, INT_MAX);
  priority_queue<pair<unsigned long long, unsigned long long>,
                 vector<pair<unsigned long long, unsigned long long> >,
                 greater<pair<unsigned long long, unsigned long long> > >
      pq;
  pq.push({0, s});
  dist[s] = 0;
  while (!pq.empty()) {
    auto tp = pq.top();
    pq.pop();
    if (vis[tp.second]) continue;
    vis[tp.second] = 1;
    for (auto i : node[tp.second]) {
      if (dist[tp.second] + 1 < dist[i]) {
        dist[i] = dist[tp.second] + 1;
        pq.push({dist[i], i});
      }
    }
  }
  return dist[d];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  unsigned long long n;
  cin >> n;
  vector<unsigned long long> arr(n);
  for (unsigned long long i = 0; i < n; i++) cin >> arr[i];
  unsigned long long ans = INT_MAX;
  for (unsigned long long i = 0; i < 64; i++) {
    unsigned long long set_bit = 0;
    vector<unsigned long long> conn;
    for (unsigned long long j = 0; j < n; j++) {
      if ((arr[j] & (1LL << i))) {
        set_bit++;
        conn.push_back(j);
      }
    }
    if (set_bit > 2) {
      cout << 3;
      return 0;
    } else if (set_bit == 2) {
      unsigned long long x, y;
      x = conn[0];
      y = conn[1];
      unsigned long long val = djikstra(x, y);
      if (val == 1) continue;
      ans = min(ans, val + 1);
      node[x].push_back(y);
      node[y].push_back(x);
    }
  }
  if (ans == INT_MAX)
    cout << -1;
  else
    cout << ans;
  return 0;
}
