#include <bits/stdc++.h>
using namespace std;
vector<long long int> v[200000], graph[200000];
long long int bfs(long long int i, long long int j) {
  map<long long int, long long int> mm;
  queue<pair<long long int, long long int> > q;
  q.push({i, 1});
  mm[i]++;
  while (!q.empty()) {
    long long int u = q.front().first;
    long long int w = q.front().second;
    q.pop();
    if (u == j) {
      return w;
    }
    for (long long int k = 0; k < graph[u].size(); k++) {
      if (graph[u][k] == j && u == i) {
        continue;
      }
      if (mm[graph[u][k]] == 0) {
        mm[graph[u][k]]++;
        q.push({graph[u][k], w + 1});
      }
    }
  }
  return 1000;
}
int main() {
  long long int t, i, j, k, m, n;
  cin >> n;
  long long int ar[n];
  for (i = 0; i < n; i++) {
    cin >> ar[i];
  }
  long long int bit[61] = {0};
  for (i = 0; i < n; i++) {
    k = ar[i];
    for (j = 0; j <= 60; j++) {
      if (k & 1) {
        bit[j]++;
        v[j].push_back(i);
      }
      k /= 2;
    }
  }
  for (i = 0; i <= 60; i++) {
    if (bit[i] >= 3) {
      cout << 3;
      return 0;
    }
  }
  for (i = 0; i <= 60; i++) {
    if (v[i].size() == 2) {
      graph[v[i][0]].push_back(v[i][1]);
      graph[v[i][1]].push_back(v[i][0]);
    }
  }
  long long int ans = 1000;
  for (i = 0; i <= 60; i++) {
    if (v[i].size() == 2) {
      j = bfs(v[i][0], v[i][1]);
      ans = min(ans, j);
    }
  }
  if (ans == 1000) {
    ans = -1;
  }
  cout << ans;
  return 0;
}
