#include <bits/stdc++.h>
using namespace std;
void debug() { cout << endl; }
template <class T, class... R>
void debug(T f, R... r) {
  cout << "[" << f << "]";
  debug(r...);
}
template <class T>
T mmin(T a, T b) {
  return min(a, b);
}
template <class T, class... R>
T mmin(T a, R... b) {
  return min(a, mmin(b...));
}
template <class T>
T mmax(T a, T b) {
  return max(a, b);
}
template <class T, class... R>
T mmax(T a, R... b) {
  return max(a, mmax(b...));
}
template <class T>
T mgcd(T a, T b) {
  return __gcd(a, b);
}
template <class T, class... R>
T mgcd(T a, R... b) {
  return __gcd(a, mgcd(b...));
}
void myin() {
  freopen("1.in", "r", stdin);
  freopen("1.out", "w", stdout);
}
namespace IO {
const int MX = 4e7;
char buf[MX];
int c, sz;
void begin() {
  c = 0;
  sz = fread(buf, 1, MX, stdin);
}
inline bool read(int &t) {
  while (c < sz && buf[c] != '-' && (buf[c] < '0' || buf[c] > '9')) c++;
  if (c >= sz) return false;
  bool flag = 0;
  if (buf[c] == '-') flag = 1, c++;
  for (t = 0; c < sz && '0' <= buf[c] && buf[c] <= '9'; c++)
    t = t * 10 + buf[c] - '0';
  if (flag) t = -t;
  return true;
}
}  // namespace IO
const int N = 1e5 + 5;
const int M = 1e5 + 5;
long long a[100005], e[200][200];
vector<long long> v, sz[100];
int main() {
  long long n;
  scanf("%lld", &n);
  for (long long i = 1; i <= n; ++i) {
    long long tmp;
    scanf("%lld", &a[i]);
    if (a[i]) v.push_back(a[i]);
    for (long long j = 0; j < 63; ++j) {
      if ((1ll << j) & a[i]) sz[j].push_back(a[i]);
    }
  }
  for (long long i = 0; i < 63; ++i)
    if (sz[i].size() > 2) {
      return !printf("3");
    }
  memset(e, 0x3f, sizeof(e));
  long long ans = 0x3f3f3f3f3f3f3f3f;
  for (long long i = 0; i < v.size(); ++i) {
    for (long long j = 0; j < v.size(); ++j) {
      if (i != j && (v[i] & v[j])) e[i][j] = 1;
    }
  }
  for (long long k = 0; k < v.size(); ++k) {
    for (long long i = 0; i < v.size(); ++i) {
      for (long long j = 0; j < v.size(); ++j) {
        if (i == j || i == k || j == k) continue;
        if ((v[i] & v[k] && v[k] & v[j])) ans = min(ans, e[i][j] + 2);
      }
    }
    for (long long i = 0; i < v.size(); ++i) {
      for (long long j = 0; j < v.size(); ++j) {
        e[i][j] = min(e[i][j], e[i][k] + e[k][j]);
      }
    }
  }
  if (ans == 0x3f3f3f3f3f3f3f3f) ans = -1;
  printf("%lld\n", ans);
  return 0;
}
