#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
long long a[maxn];
int mp[250][250];
int dis[250][250];
int res = 99999999;
int n;
void floyd() {
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < k; i++) {
      for (int j = i + 1; j < k; j++) {
        res = min(res, dis[i][j] + mp[j][k] + mp[k][i]);
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        dis[i][j] = dis[j][i] = min(dis[i][j], dis[i][k] + dis[k][j]);
      }
    }
  }
}
int main() {
  scanf("%d", &n);
  int num = 0;
  for (int i = 0; i < n; i++) {
    long long tot;
    scanf("%I64d", &tot);
    if (tot != 0) {
      a[num] = tot;
      num++;
    }
  }
  if (num >= 200) return 0 * printf("3\n");
  n = num;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      mp[i][j] = mp[j][i] = 10000000;
      dis[i][j] = dis[j][i] = 10000000;
    }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (i != j && (a[i] & a[j]) > 0) {
        mp[i][j] = mp[j][i] = 1;
        dis[i][j] = dis[j][i] = 1;
      }
    }
  }
  for (int i = 0; i < n; i++) dis[i][i] = mp[i][i] = 0;
  floyd();
  if (res > 100000)
    cout << "-1" << endl;
  else
    cout << res << endl;
}
