#include <bits/stdc++.h>
using namespace std;
map<long long int, vector<long long int> > g;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<long long int> a;
  for (int i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    if (x != 0) a.push_back(x);
  }
  n = a.size();
  if (n <= 150) {
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        if ((a[i] & a[j])) {
          g[i].push_back(j);
          g[j].push_back(i);
        }
      }
    }
    long long int ans = 1e10;
    for (int i = 0; i < n; i++) {
      vector<long long int> dist(n, 1e6), par(n, -1);
      dist[i] = 0;
      set<pair<long long int, long long int> > s;
      s.insert({0, i});
      while (s.size() != 0) {
        pair<long long int, long long int> p = *s.begin();
        s.erase(s.begin());
        long long int x = p.second;
        for (int i = 0; i < g[x].size(); i++) {
          int c = g[x][i];
          if (dist[x] + 1 < dist[c]) {
            par[c] = x;
            dist[c] = dist[x] + 1;
            s.insert({dist[c], c});
          } else if (par[c] != x && par[x] != c) {
            ans = min(ans, dist[c] + dist[x] + 1);
          }
        }
      }
    }
    if (ans == 1e10) ans = -1;
    cout << ans;
  } else {
    cout << 3;
  }
}
