#include <bits/stdc++.h>
using namespace std;
const int maxn = 305000;
const int inf = 2e9;
int n;
long long int A[maxn], B[maxn];
vector<int> G[maxn];
long long int d[1050][1050], mp[1050][1050];
int main() {
  cin >> n;
  for (int i = 1; i <= 500; ++i)
    for (int j = 1; j <= 500; ++j) d[i][j] = mp[i][j] = inf;
  for (int i = 1; i <= n; ++i) cin >> A[i];
  int num = 0;
  for (int i = 1; i <= n; i++) {
    if (A[i]) B[++num] = A[i];
  }
  n = num;
  for (int i = 1; i <= n; i++) A[i] = B[i];
  if (n >= 300) {
    cout << 3;
    return 0;
  } else {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (A[i] & A[j]) d[i][j] = d[j][i] = mp[i][j] = mp[j][i] = 1;
      }
    }
    long long int MinCost = inf;
    for (int k = 1; k <= n; k++) {
      for (int i = 1; i < k; i++)
        for (int j = i + 1; j < k; j++)
          MinCost = min(MinCost, ((d[i][j] + mp[i][k] + mp[k][j]) >= 3
                                      ? (d[i][j] + mp[i][k] + mp[k][j])
                                      : inf));
      for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }
    if (MinCost == inf)
      cout << -1;
    else
      cout << MinCost << endl;
  }
}
