#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 120, lg = 60, inf = 1e9;
int n, d[maxn], par[maxn], cnt[maxn];
long long a[maxn];
vector<int> g[maxn];
int ans = inf;
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    for (int j = 0; j < lg; j++)
      if (a[i] >> j & 1) cnt[j]++;
    if (!a[i]) i--, n--;
  }
  for (int i = 0; i < lg; i++)
    if (cnt[i] > 2) return cout << "3\n", 0;
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      if (a[i] & a[j]) {
        queue<int> q;
        fill(d, d + n, inf);
        d[j] = 0;
        for (int k = 0; k < n; k++)
          if ((a[j] & a[k]) && k != i && k != j) d[k] = 1, q.push(k);
        while (q.size()) {
          int v = q.front();
          q.pop();
          for (int u = 0; u < n; u++)
            if (a[v] & a[u])
              if (d[u] > d[v] + 1) {
                q.push(u);
                d[u] = d[v] + 1;
              }
        }
        ans = min(ans, d[i] + 1);
      }
  if (ans != inf)
    cout << ans << '\n';
  else
    cout << "-1\n";
}
