#include <bits/stdc++.h>
using namespace std;
int n;
long long a[100005];
vector<vector<int>> graph(200);
int dist(int x, int y) {
  vector<int> d(200, 2000000000);
  queue<int> Q;
  d[x] = 0;
  Q.push(x);
  while (!Q.empty()) {
    int f = Q.front();
    Q.pop();
    for (int i : graph[f]) {
      if (f == x && i == y) continue;
      if (d[i] > d[f] + 1) {
        d[i] = d[f] + 1;
        Q.push(i);
      }
    }
  }
  return d[y];
}
int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      i--;
      n--;
    }
  }
  for (int i = 0; i < 60; i++) {
    int cnt = 0;
    for (int k = 0; k < n; k++)
      if ((a[k] >> i) & 1) cnt++;
    if (cnt >= 3) {
      cout << 3 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (a[i] & a[j]) {
        graph[i].push_back(j);
        graph[j].push_back(i);
      }
    }
  }
  int ans = 2000000000;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (a[i] & a[j]) {
        ans = min(ans, dist(i, j) + 1);
      }
    }
  }
  if (ans == 2000000000) ans = -1;
  cout << ans << endl;
  return 0;
}
