#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int mod_ = 998244353;
const int INF = 1000000000;
const long long int INF64 = (long long int)1E18;
int n;
vector<vector<int> > graph;
inline int bfs_sd(int start, int end) {
  queue<int> q;
  vector<bool> visited(n + 1);
  vector<int> distance(n + 1);
  visited[start] = true;
  distance[start] = 0;
  q.push(start);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int v : graph[u]) {
      if (!visited[v]) {
        visited[v] = true;
        distance[v] = distance[u] + 1;
        if (v == end) {
          return distance[v];
        }
        q.push(v);
      }
    }
  }
  return INF;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  vector<long long int> arr, cnt(61);
  for (int j = 0; j < n; j++) {
    long long int ele;
    cin >> ele;
    if (!ele) continue;
    for (int i = 0; i < 61; i++) {
      if (ele & (1LL << i)) cnt[i]++;
    }
    arr.push_back(ele);
  }
  n = arr.size();
  if (*max_element(cnt.begin(), cnt.end()) >= 3) {
    cout << 3;
    return 0;
  }
  graph.resize(n);
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (arr[i] & arr[j]) {
        graph[i].push_back(j);
        graph[j].push_back(i);
      }
    }
  }
  int min_cycle_len = INF;
  for (int u = 0; u < n; u++) {
    for (int v = u + 1; v < n; v++) {
      if (find(graph[u].begin(), graph[u].end(), v) == graph[u].end()) continue;
      graph[u].erase(find(graph[u].begin(), graph[u].end(), v));
      graph[v].erase(find(graph[v].begin(), graph[v].end(), u));
      int curr_cycle_len = bfs_sd(u, v) + 1;
      min_cycle_len = min(min_cycle_len, curr_cycle_len);
      graph[u].push_back(v);
      graph[v].push_back(u);
    }
  }
  cout << (min_cycle_len == INF ? -1 : min_cycle_len);
  return 0;
}
