#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
long long ai[100000 + 100];
vector<long long> a;
int n, d[200][200], dist[200][200];
int main() {
  cin >> n;
  a.push_back(0);
  for (int i = 1; i <= n; i++) {
    cin >> ai[i];
    if (ai[i]) a.push_back(ai[i]);
  }
  n = a.size() - 1;
  memset(d, INF, sizeof(d));
  memset(dist, INF, sizeof(d));
  if (n > 120) {
    cout << 3 << endl;
    exit(0);
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      if (i == j)
        dist[i][j] = d[i][j] = 0;
      else if (a[i] & a[j])
        dist[i][j] = d[i][j] = 1;
    }
  int ans = INF;
  for (int k = 1; k <= n; k++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) {
        if (k > i && k > j && i != j) {
          ans =
              min((long long)ans, (long long)d[i][j] + dist[i][k] + dist[k][j]);
        }
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
  if (ans == INF) ans = -1;
  cout << ans << endl;
  exit(0);
}
