#include <bits/stdc++.h>
using namespace std;
const int inf = 200;
long long n, a[100005];
int dis[250][250], mp[250][250];
void init() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    if (a[i] == 0) i--, n--;
  }
}
void Floyd() {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if ((a[i] & a[j]) && i != j)
        dis[i][j] = mp[i][j] = 1;
      else
        dis[i][j] = mp[i][j] = inf;
    }
  }
  int ans = inf;
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i < k; i++)
      for (int j = i + 1; j < k; j++)
        if (ans > dis[i][j] + mp[i][k] + mp[k][j])
          ans = 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]);
  }
  if (ans > n)
    printf("-1\n");
  else
    printf("%d", ans);
}
int main() {
  init();
  if (n >= 130)
    cout << 3 << endl;
  else
    Floyd();
  return 0;
}
