#include <bits/stdc++.h>
using namespace std;
vector<long long int> bit[63];
long long int ans = 2000000000;
void includbit(long long int n, long long int ind) {
  for (long long int i = 0; i < 63; i++) {
    if ((((n) & (1LL << (i))) != 0)) bit[i].push_back(ind);
  }
}
vector<long long int> adj[500005];
long long int bfs(long long int ind) {
  queue<long long int> q;
  q.push(ind);
  vector<long long int> vis(500005, 0);
  vector<long long int> dis(500005, 0);
  vector<long long int> par(500005, -1);
  vis[ind] = 1;
  par[ind] = -1;
  while (!q.empty()) {
    long long int y = q.front();
    q.pop();
    for (int i = 0; i < adj[y].size(); i++) {
      if (vis[adj[y][i]]) {
        if (par[y] != adj[y][i]) return dis[y] + dis[adj[y][i]] + 1;
        continue;
      }
      dis[adj[y][i]] = dis[y] + 1;
      vis[adj[y][i]] = 1;
      par[adj[y][i]] = y;
      q.push(adj[y][i]);
    }
  }
  return 2000000000;
}
long long int root;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  for (int qq = 1; qq <= T; qq++) {
    int n;
    cin >> n;
    vector<long long int> v;
    for (int i = 0; i < n; i++) {
      long long int x;
      cin >> x;
      if (x) v.push_back(x);
      if (x) includbit(x, i);
    }
    for (int i = 0; i < 63; i++) {
      if (bit[i].size() >= 3) {
        cout << 3 << endl;
        return 0;
      }
    }
    long long int ans = 2000000000;
    for (int i = 0; i < v.size(); i++) {
      for (int j = i + 1; j < v.size(); j++) {
        if (v[i] & v[j]) {
          adj[i].push_back(j);
          adj[j].push_back(i);
        }
      }
    }
    for (int i = 0; i < v.size(); i++) {
      root = i;
      ans = min(ans, bfs(i));
    }
    if (ans == 2000000000)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
