#include <bits/stdc++.h>
using namespace std;
const int maxn = 251;
const int inf = 0x3f3f3f3f;
long long dis[maxn][maxn];
long long a[maxn];
long long cost[maxn][maxn];
int main() {
  int n;
  long long cnt = 1;
  long long minn = inf;
  long long t;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &t);
    if (t != 0) a[cnt++] = t;
    if (cnt > 250) break;
  }
  if (cnt > 250) {
    cout << "3" << endl;
    return 0;
  }
  for (int i = 1; i < cnt; i++) {
    for (int j = i + 1; j < cnt; j++) {
      if (a[i] & a[j]) {
        dis[i][j] = dis[j][i] = 1;
        cost[i][j] = cost[j][i] = 1;
      } else {
        cost[i][j] = cost[j][i] = inf;
        dis[i][j] = dis[j][i] = inf;
      }
    }
  }
  for (int k = 1; k < cnt; k++) {
    for (int i = 1; i < k; i++) {
      for (int j = i + 1; j < k; j++) {
        minn = min(minn, dis[i][j] + cost[i][k] + cost[k][j]);
      }
    }
    for (int i = 1; i < cnt; i++) {
      for (int j = 1; j < cnt; j++) {
        dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
      }
    }
  }
  if (minn != inf)
    cout << minn << endl;
  else
    cout << "-1" << endl;
}
