#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
using namespace std;
const long long one = 1;
const long double INF = 2e9 + 100;
const long long MOD = 1e9 + 7;
const long long N = 2e5 + 100;
const long long nul = 0;
const long long SIZE = 1e6 * 3;
long long n;
long long a[N];
vector<long long> smth;
long long dist[300][300], gr[300][300];
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i]) smth.push_back(a[i]);
  }
  n = smth.size();
  if (n >= 200) {
    cout << 3 << endl;
    return 0;
  }
  long long ans = INF;
  for (long long i = 0; i < 300; i++) {
    for (long long j = 0; j < 300; j++) {
      dist[i][j] = gr[i][j] = INF;
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = i + 1; j < n; j++) {
      if (smth[i] & smth[j]) {
        dist[i][j] = gr[i][j] = dist[j][i] = gr[j][i] = 1;
      }
    }
  }
  for (long long k = 0; k < n; k++) {
    for (long long i = 0; i < k; i++) {
      for (long long j = 0; j < i; j++) {
        ans = min(ans, gr[i][k] + gr[k][j] + dist[i][j]);
      }
    }
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < n; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  if (ans == INF)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
