#include <bits/stdc++.h>
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &xs) {
  for (auto &x : xs) is >> x;
  return is;
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &xs) {
  for (auto it = xs.begin(); it != xs.end(); ++it) {
    os << "[ "[it != xs.begin()] << *it << ",]"[it == --xs.end()];
  }
  return os;
}
auto common(const std::set<int> &lhs, const std::set<int> &rhs) -> int {
  for (auto x : lhs) {
    if (rhs.count(x) != 0) {
      return x;
    }
  }
  return -1;
}
using Graph = std::vector<std::set<int>>;
struct BFS {
  const Graph &graph;
  std::vector<int> times;
  BFS(const Graph &graph) : graph(graph), times(graph.size(), -1) {}
  void fill(int root) {
    times = std::vector<int>(graph.size(), -1);
    times[root] = 0;
    std::queue<int> queue;
    queue.push(root);
    for (; !queue.empty(); queue.pop()) {
      auto v = queue.front();
      for (auto u : graph[v]) {
        if (times[u] != -1) continue;
        times[u] = times[v] + 1;
        queue.push(u);
      }
    }
  }
};
auto main() -> int {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n;
  std::cin >> n;
  std::vector<int64_t> xs(n);
  std::cin >> xs;
  std::vector<std::set<int>> by_bits(60, std::set<int>{});
  for (int64_t i = 0, bit = 1; i < 60; ++i, bit <<= 1) {
    for (int j = 0; j < n; ++j) {
      if (bit & xs[j]) {
        by_bits[i].insert(j);
      }
    }
  }
  for (auto &lvl : by_bits) {
    if (lvl.size() >= 3) {
      std::cout << 3 << '\n';
      return 0;
    }
    if (lvl.size() == 1) {
      lvl = {};
    }
  }
  auto graph = Graph(n);
  for (int i = 0; i < 60; ++i)
    for (int j = i + 1; j < 60; ++j) {
      if (by_bits[i] == by_bits[j]) {
        by_bits[j] = {};
      }
    }
  for (auto &lvl : by_bits) {
    for (auto x : lvl)
      for (auto y : lvl)
        if (x < y) {
          graph[x].insert(y);
          graph[y].insert(x);
        }
  }
  auto upd = [](int &x, int value) {
    if (x == -1) x = value;
    x = std::min(x, value);
  };
  int answer = -1;
  for (int v = 0; v < n; ++v) {
    auto links = graph[v];
    for (auto u : links) {
      graph[v].erase(u);
      auto bfs = BFS(graph);
      bfs.fill(v);
      if (bfs.times[u] != -1) {
        upd(answer, 1 + bfs.times[u]);
      }
      graph[v].insert(u);
    }
  }
  std::cout << answer << '\n';
  return 0;
}
