#include <bits/stdc++.h>
using namespace std;
const int M = 150;
int ej[M][M];
const int inf = 1e9;
int n;
int bfs(int src, int sink) {
  vector<int> vis(n, 0);
  vector<int> dis(n, 0);
  queue<int> que;
  vis[src] = 1;
  que.push(src);
  while (que.size() > 0) {
    int u = que.front();
    que.pop();
    for (int v = 0; v < n; v++) {
      if (vis[v] == 0 && ej[u][v] == 1) {
        vis[v] = 1;
        dis[v] = dis[u] + 1;
        que.push(v);
        if (v == sink) return dis[v];
      }
    }
  }
  return -1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  vector<long long> v;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    if (x) v.push_back(x);
  }
  n = v.size();
  for (long long k = 0; k < 62; k++) {
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      if (v[i] & (1LL << k)) {
        cnt++;
      }
    }
    if (cnt >= 3) {
      cout << 3 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      if ((v[i] & v[j]) > 0) ej[i][j] = 1;
    }
  }
  int ans = inf;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (ej[i][j] == 0) continue;
      ej[i][j] = 0;
      ej[j][i] = 0;
      int cur = bfs(i, j);
      if (cur != -1) {
        ans = min(ans, cur + 1);
      }
      ej[i][j] = 1;
      ej[j][i] = 1;
    }
  }
  if (ans == inf) ans = -1;
  cout << ans << endl;
  return 0;
}
