#include <bits/stdc++.h>
using namespace std;
int const nmax = 1e5;
int ans = 1e5 + 2;
int n, dist[nmax], par[nmax], used[nmax];
queue<int> qu;
set<int> s;
vector<int> g[nmax];
void searchcycle() {
  for (int v = 0; v < n; v++) {
    dist[v] = 0;
    par[v] = -1;
    for (int i = 0; i < n; i++) used[i] = 0;
    qu = queue<int>();
    qu.push(v);
    while (!qu.empty()) {
      int x = qu.front();
      qu.pop();
      used[x] = 1;
      for (int i = 0; i < g[x].size(); i++) {
        int to = g[x][i];
        if (to == par[x]) continue;
        if (!used[to]) {
          par[to] = x;
          qu.push(to);
          dist[to] = dist[x] + 1;
        } else {
          if (dist[x] + dist[to] + 1 > 2) {
            ans = min(ans, dist[x] + dist[to] + 1);
          }
        }
      }
    }
  }
}
int main() {
  long long in;
  vector<long long> a;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &in);
    if (in) a.push_back(in);
  }
  if (a.size() > 126) {
    printf("3");
    return 0;
  }
  n = a.size();
  for (int i = 0; i < a.size() - 1; i++) {
    for (int j = i + 1; j < a.size(); j++) {
      if (a[i] & a[j]) {
        g[i].push_back(j);
        g[j].push_back(i);
      }
    }
  }
  searchcycle();
  if (ans != 1e5 + 2 && ans > 2)
    printf("%d", ans);
  else
    printf("-1");
  return 0;
}
