#include <bits/stdc++.h>
using namespace std;
long long n, arr[100005], dis[505][505], e[505][505], ans;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> arr[i];
    if (arr[i] == 0) {
      n--;
      i--;
    }
  }
  if (n > 3 * 64) {
    cout << 3 << endl;
    return 0;
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = i + 1; j <= n; j++) {
      if (arr[i] & arr[j]) {
        dis[i][j] = 1;
        dis[j][i] = 1;
        e[i][j] = 1;
        e[j][i] = 1;
      } else {
        dis[i][j] = 2e9;
        dis[j][i] = 2e9;
        e[i][j] = 2e9;
        e[j][i] = 2e9;
      }
    }
  }
  ans = 2e9;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j < i; j++) {
      for (long long k = j + 1; k < i; k++) {
        ans = min(ans, e[j][i] + e[i][k] + dis[j][k]);
      }
    }
    for (long long j = 1; j <= n; j++) {
      for (long long k = 1; k <= n; k++) {
        dis[j][k] = min(dis[j][k], dis[j][i] + dis[i][k]);
      }
    }
  }
  if (ans > 1000)
    cout << "-1\n";
  else
    cout << ans << endl;
}
