#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long nums[100000];
  int n;
  map<int, vector<unsigned long long>> freq;
  map<unsigned long long, vector<unsigned long long>> vertices;
  long long max_cycle_length = 1e9 + 10;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> nums[i];
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 60; j++) {
      if (1ULL << j & nums[i]) {
        freq[j].push_back(nums[i]);
      }
    }
  }
  for (int i = 0; i < 60; ++i) {
    if (freq[i].size() >= 3) {
      cout << 3 << endl;
      return 0;
    }
  }
  for (int i = 0; i < 60; ++i) {
    if (freq[i].size() == 2) {
      vertices[freq[i][0]].push_back(freq[i][1]);
      vertices[freq[i][1]].push_back(freq[i][0]);
    }
  }
  function<long long(unsigned long long, unsigned long long)> bfs =
      [&](unsigned long long source, unsigned long long target) {
        queue<unsigned long long> q;
        unsigned long long next_vertex;
        map<unsigned long long, unsigned long long> distances;
        map<unsigned long long, bool> visited;
        for (const auto &z : visited) {
          visited[z.first] = false;
          distances[z.first] = 0;
        }
        q.push(source);
        while (!q.empty()) {
          next_vertex = q.front();
          q.pop();
          for (const auto &z : vertices[next_vertex]) {
            if (!visited[z] && next_vertex == source && z == target) {
              continue;
            }
            if (!visited[z]) {
              visited[z] = true;
              distances[z] = distances[next_vertex] + 1;
              q.push(z);
            }
          }
        }
        return distances[target] == 0 ? 1e9 + 10 : distances[target] + 1;
      };
  for (const auto &x : vertices) {
    for (const auto &y : x.second) {
      max_cycle_length = min(bfs(x.first, y), max_cycle_length);
    }
  }
  if (max_cycle_length == 1e9 + 10)
    cout << "-1" << endl;
  else
    cout << max_cycle_length << endl;
  return 0;
}
