#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main() {
  ll n;
  cin >> n;
  vector<ll> a;
  for (ll i = 0; i < n; i++) {
    ll c;
    cin >> c;
    if (c > 0) a.push_back(c);
  }
  if (a.size() >= 200) {
    cout << 3 << endl;
    return 0;
  }
  n = a.size();
  vector<vector<ll> > adj(n + 1);
  vector<vector<int> > visited(n + 1, vector<int>(n + 1));
  for (ll i = 0; i < n; i++) {
    for (ll j = i + 1; j < n; j++) {
      for (ll k = 0; k < 63; k++) {
        ll val = 1ll << k;
        if (val & a[j] && val & a[i]) {
          adj[i + 1].push_back(j + 1);
          adj[j + 1].push_back(i + 1);
          break;
        }
      }
    }
  }
  ll ans = 1e9;
  for (ll i = 1; i <= n; i++) {
    vector<ll> visited(n + 1, 0);
    vector<ll> dp(n + 1, 0);
    queue<ll> q;
    visited[i] = 1;
    q.push(i);
    vector<ll> parent(n + 1, -1);
    while (!q.empty()) {
      ll p = q.front();
      q.pop();
      for (auto it : adj[p]) {
        if (!visited[it]) {
          q.push(it);
          parent[it] = p;
          visited[it] = 1;
          dp[it] = dp[p] + 1;
        } else {
          if (it != parent[p]) {
            ans = min(ans, dp[it] + dp[p] + 1);
          }
        }
      }
    }
  }
  if (ans == 1e9)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
