#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int INF = 1000000000;
vector<vector<int>> g;
int n;
int mn = INF;
inline void bfs(int start) {
  vector<int> dist(n, INF);
  vector<int> fat(n);
  deque<int> q;
  q.push_back(start);
  dist[start] = 0;
  while (!q.empty()) {
    int v = q.front();
    q.pop_front();
    for (auto u : g[v]) {
      if (dist[u] == INF) {
        fat[u] = v;
        dist[u] = dist[v] + 1;
        q.push_back(u);
      } else {
        if (fat[v] != u) mn = min(mn, dist[v] + dist[u]);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n;
  int k = 60;
  int rg[k];
  for (int i = 0; i < k; ++i) rg[i] = 0;
  long long dv[k];
  dv[0] = 1;
  for (int i = 1; i < k; ++i) dv[i] = dv[i - 1] << 1;
  long long old[n];
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    cin >> old[i];
    if (old[i] == 0) cnt++;
  }
  long long ar[n - cnt];
  cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (old[i] != 0) ar[cnt++] = old[i];
  }
  n = cnt;
  for (int u = 0; u < n; ++u) {
    for (long long i = 0; i < k; ++i) {
      if ((ar[u] | dv[i]) == ar[u]) {
        rg[i]++;
      }
    }
  }
  for (auto i : rg) {
    if (i >= 3) {
      cout << 3 << '\n';
      return 0;
    }
  }
  g.resize(n);
  for (int u = 0; u < n; ++u)
    for (int v = u + 1; v < n; ++v) {
      if ((ar[u] & ar[v]) != 0) {
        g[u].push_back(v);
        g[v].push_back(u);
      }
    }
  for (int i = 0; i < n; ++i) {
    bfs(i);
  }
  if (mn == INF)
    cout << -1 << '\n';
  else
    cout << mn + 1 << '\n';
  return 0;
}
