#include <bits/stdc++.h>
using namespace std;
const int maxm = 205;
const int maxn = 2e5 + 15;
const int inf = 1e8 + 178;
int n, mp[maxm][maxm], dis[maxm][maxm];
long long a[maxn], val;
void BuildEdge() {
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if ((a[i] & a[j]) && i != j)
        mp[i][j] = dis[i][j] = 1;
      else
        mp[i][j] = dis[i][j] = inf;
    }
  }
}
int Floyd() {
  int res = inf;
  for (int k = 1; k <= n; ++k) {
    for (int i = 1; i < k; ++i)
      for (int j = i + 1; j < k; ++j)
        res = min(res, dis[i][j] + mp[i][k] + mp[k][j]);
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= n; ++j)
        dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
  }
  return res;
}
int solve() {
  BuildEdge();
  int res = Floyd();
  return res > n ? -1 : res;
}
int main() {
  cin >> n;
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> val;
    if (val != 0) a[++cnt] = val;
  }
  n = cnt;
  if (n >= 200)
    puts("3");
  else
    cout << solve() << '\n';
  return 0;
}
