#include <bits/stdc++.h>
int n;
std::vector<long long int> vertices;
std::vector<std::vector<int>> edges;
const int bitlimit = 63;
std::vector<int> channels[bitlimit];
template <typename thistype>
void makeUnique(std::vector<thistype> &another) {
  std::sort(another.begin(), another.end());
  auto ptr = std::unique(another.begin(), another.end());
  another.erase(ptr, another.end());
}
int shortestBFS(int root) {
  const int unreachable = 987654321;
  std::set<std::pair<int, int>> checked;
  std::vector<std::vector<int>> distances(n);
  distances[root].push_back(0);
  int level = 0;
  std::vector<std::pair<int, int>> nowlook;
  for (auto first : edges[root])
    nowlook.push_back({root, first}), checked.insert({root, first});
  while (!nowlook.empty()) {
    level++;
    std::vector<std::pair<int, int>> nextlook;
    for (auto nowinfo : nowlook) {
      int now = nowinfo.second, prev = nowinfo.first;
      distances[now].push_back(level);
      for (auto next : edges[now])
        if (checked.find({now, next}) == checked.end() &&
            checked.find({next, now}) == checked.end())
          nextlook.push_back({now, next}), checked.insert({now, next});
    }
    makeUnique<std::pair<int, int>>(nextlook);
    nowlook = nextlook;
  }
  int answer = unreachable;
  for (int i = 0; i < n; i++) {
    if (distances[i].size() >= 2) {
      std::sort(distances[i].begin(), distances[i].end());
      int thisanswer = distances[i][0] + distances[i][1];
      if (answer > thisanswer) answer = thisanswer;
    }
  }
  return answer == unreachable ? -1 : answer;
}
int main(void) {
  scanf("%d", &n);
  vertices.resize(n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &vertices[i]);
    for (int b = 0; b < bitlimit; b++)
      if (vertices[i] & (1LL << b)) channels[b].push_back(i);
  }
  for (int b = 0; b < bitlimit; b++) {
    if (channels[b].size() >= 3) {
      printf("%d\n", 3);
      return 0;
    }
  }
  edges.resize(n);
  for (int b = 0; b < bitlimit; b++)
    if (channels[b].size() == 2) {
      edges[channels[b][0]].push_back(channels[b][1]);
      edges[channels[b][1]].push_back(channels[b][0]);
    }
  for (int i = 0; i < n; i++) makeUnique<int>(edges[i]);
  const int error = 987654321;
  int minimal = error;
  for (int i = 0; i < n; i++)
    if (!edges[i].empty()) {
      int thisanswer = shortestBFS(i);
      if (thisanswer > 0 && thisanswer < minimal) minimal = thisanswer;
    }
  printf("%d\n", minimal == error ? -1 : minimal);
  return 0;
}
