#include <bits/stdc++.h>
using namespace std;
long long a[(long long)1e5 + 2];
long long k[1000];
vector<long long> g[10000];
long long s[10000], used[10000], pre[10000];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      i--;
      n--;
    }
  }
  for (long long i = 0; i < n; i++) {
    long long x = a[i];
    long long cnt = 0;
    while (x > 0) {
      if (x % 2) k[cnt]++;
      x /= 2;
      cnt++;
    }
  }
  for (long long i = 0; i < 500; i++) {
    if (k[i] >= 3) {
      cout << 3;
      return 0;
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = i + 1; j < n; j++) {
      if (a[i] & a[j]) {
        g[i].push_back(j);
        g[j].push_back(i);
      }
    }
  }
  long long ans = 1e9;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      s[j] = 0;
      used[j] = 0;
      pre[j] = -1;
    }
    queue<long long> q;
    q.push(i);
    s[i] = 1;
    used[i] = 1;
    while (!q.empty()) {
      long long d = q.front();
      q.pop();
      for (auto u : g[d]) {
        if (u == pre[d]) continue;
        if (!used[u]) {
          q.push(u);
          if (!s[u]) s[u] = s[d] + 1;
          pre[u] = d;
          used[u] = 1;
        } else {
          ans = min(ans, s[d] + s[u] - 1);
        }
      }
    }
  }
  if (ans == 1e9)
    cout << -1;
  else
    cout << ans;
  return 0;
}
