#include <bits/stdc++.h>
using namespace std;
struct Node {
  int index;
  vector<int> nbors;
  Node(int i) : index(i) {}
};
int shortes_cycle_with_node(const vector<Node>& nodes, int index) {
  int n = nodes.size();
  vector<bool> seen(n, false);
  vector<int> dist(n, 0);
  vector<int> parent(n, -1);
  queue<int> q;
  q.push(index);
  seen[index] = true;
  int min_cycle = INT_MAX;
  while (!q.empty()) {
    int ind_front = q.front();
    q.pop();
    const Node& node = nodes[ind_front];
    for (int i : node.nbors) {
      if (!seen[i]) {
        q.push(i);
        dist[i] = dist[ind_front] + 1;
        parent[i] = ind_front;
        seen[i] = true;
      } else if (i != index && i != parent[ind_front]) {
        int cand = dist[ind_front] + dist[i] + 1;
        min_cycle = min(min_cycle, cand);
      }
    }
  }
  return min_cycle;
}
int shortest_cycle(const vector<Node>& nodes) {
  int ans = INT_MAX;
  for (int i = 0; i < nodes.size(); ++i) {
    int cand = shortes_cycle_with_node(nodes, i);
    ans = min(cand, ans);
  }
  if (ans == INT_MAX)
    return -1;
  else
    return ans;
}
void print_graph(const vector<Node>& nodes) {
  for (const Node& n : nodes) {
    cout << "Node index=" << n.index << endl;
    cout << "Node nbors=";
    for (int i : n.nbors) cout << " " << i;
    cout << endl;
  }
}
int main() {
  int n;
  cin >> n;
  vector<long long> a_;
  for (int i = 0; i < n; ++i) {
    long long inp;
    cin >> inp;
    if (inp != 0) a_.push_back(inp);
  }
  n = a_.size();
  if (n > 200) {
    cout << 3;
    return 0;
  }
  if (n < 3) {
    cout << -1;
    return 0;
  }
  vector<Node> nodes;
  for (int i = 0; i < n; ++i) {
    Node newNode(i);
    long long elt = a_[i];
    for (int j = 0; j < n; ++j) {
      if (j != i && a_[j] & elt) {
        newNode.nbors.push_back(j);
      }
    }
    nodes.push_back(newNode);
  }
  int ans = shortest_cycle(nodes);
  cout << ans;
  return 0;
}
