#include <bits/stdc++.h>
using namespace std;
pair<int, int> actual;
int neighbor, dists[100010];
long long v[100010];
bool vis[100010];
vector<int> s[62], graph[100010], aux;
queue<pair<int, int> > q;
int bfs(int node) {
  int b, ans = 1e9;
  for (int k = 0; k < (int)graph[node].size(); k++) {
    b = graph[node][k];
    for (int i = 0; i < (int)aux.size(); i++)
      vis[aux[i]] = false, dists[aux[i]] = 1e9;
    aux.clear();
    q.push(make_pair(0, node));
    dists[node] = 0;
    while (not q.empty()) {
      actual = q.front();
      q.pop();
      if (vis[actual.second]) continue;
      vis[actual.second] = true;
      aux.emplace_back(actual.second);
      for (int i = 0; i < (int)graph[actual.second].size(); i++) {
        neighbor = graph[actual.second][i];
        if (actual.second == node and neighbor == b) continue;
        if (not vis[neighbor]) {
          if (dists[actual.second] + 1 < dists[neighbor]) {
            dists[neighbor] = dists[actual.second] + 1;
            q.push(make_pair(dists[neighbor], neighbor));
          }
        }
      }
    }
    ans = min(ans, dists[b] + 1);
  }
  return ans;
}
int main() {
  int n;
  bool nope;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &v[i]);
    dists[i] = 1e9;
    for (int j = 0; j < 62; j++) {
      if ((v[i] & (1LL << ((long long)j))) != 0LL) s[j].emplace_back(i);
    }
  }
  for (int i = 0; i < 62; i++) {
    if (s[i].size() > 2) {
      printf("3\n");
      return 0;
    }
  }
  for (int i = 0; i < 62; i++) {
    for (int j = 0; j < (int)s[i].size(); j++) {
      for (int k = j + 1; k < (int)s[i].size(); k++) {
        nope = false;
        for (int w = 0; w < (int)graph[s[i][j]].size(); w++) {
          if (graph[s[i][j]][w] == s[i][k]) nope = true;
        }
        if (nope) continue;
        graph[s[i][j]].emplace_back(s[i][k]);
        graph[s[i][k]].emplace_back(s[i][j]);
      }
    }
  }
  int ans = 1e9;
  for (int i = 0; i < n; i++) ans = min(ans, bfs(i));
  printf("%d\n", ans == 1e9 ? -1 : ans);
  return 0;
}
