#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int MX = 1e6 + 5;
long long a[MX];
int g[300][300];
int mp[300][300];
vector<long long> v;
int floyd(int n) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) mp[i][j] = g[i][j];
  }
  int ans = INT_MAX / 4;
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < k; i++) {
      for (int j = i + 1; j < k; j++) {
        ans = min(ans, g[i][j] + mp[i][k] + mp[j][k]);
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
  if (ans == INT_MAX / 4) return -1;
  return ans;
}
int cnt[100];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  for (int i = 0; i < 300; i++)
    for (int j = 0; j < 300; j++) g[i][j] = INT_MAX / 3;
  for (int i = 1; i <= n; i++) {
    int wei = 1;
    long long tt = a[i];
    while (tt) {
      if (tt % 2) cnt[wei]++;
      wei++;
      tt /= 2;
    }
  }
  for (int i = 1; i < 100; i++)
    if (cnt[i] >= 3) {
      puts("3");
      return 0;
    }
  for (int i = 1; i <= n; i++) {
    if (a[i]) v.push_back(a[i]);
  }
  for (int i = 0; i < v.size(); i++) {
    for (int j = i + 1; j < v.size(); j++) {
      if ((v[i] & v[j]) != 0) g[i][j] = g[j][i] = 1;
    }
  }
  cout << floyd(v.size()) << '\n';
  return 0;
}
