#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e5 + 9, MX = 1e9 + 9;
long long n, ans = MX, dis[inf];
queue<long long> q;
vector<long long> a;
vector<pair<long long, long long> > edges, adj[inf];
int main() {
  scanf("%I64d", &n);
  for (long long i = 1; i <= n; i++) {
    long long tmp;
    scanf("%I64d", &tmp);
    if (tmp) a.push_back(tmp);
  }
  n = a.size();
  if (n >= 200) cout << 3 << endl, exit(0);
  for (long long i = 0; i < n; i++)
    for (long long j = i + 1; j < n; j++)
      if (a[i] & a[j])
        adj[i].push_back(make_pair(j, edges.size())),
            adj[j].push_back(make_pair(i, edges.size())),
            edges.push_back(make_pair(i, j));
  for (long long i = 0; i < edges.size(); i++) {
    memset(dis, -1, sizeof(dis));
    q.push(edges[i].first);
    dis[edges[i].first] = 0;
    while (!q.empty()) {
      long long cur = q.front();
      q.pop();
      for (auto o : adj[cur]) {
        long long idx = o.second, to = o.first;
        if (idx == i) continue;
        if (idx != i && dis[to] == -1) dis[to] = dis[cur] + 1, q.push(to);
      }
    }
    if (dis[edges[i].second] != -1) ans = min(ans, dis[edges[i].second] + 1);
  }
  if (ans == MX) ans = -1;
  printf("%I64d\n", ans);
}
