#include <bits/stdc++.h>
using namespace std;
const int maxn1 = 1e5 + 5;
const int maxn = 150;
const int maxm = maxn * maxn;
int n, m = 0, ok[maxn][maxn];
struct edge {
  int u, v;
} e[maxm];
set<int> adj[maxn];
bitset<maxn> b[maxn];
long long a[maxn1];
void input() {
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j < i; ++j) {
      if ((a[i] & a[j])) {
        int u, v;
        u = i;
        v = j;
        e[i].u = u;
        e[i].v = v;
        if (u == v) continue;
        adj[u].insert(v);
        adj[v].insert(u);
        ok[u][v] = ok[v][u] = 1;
        b[u].set(v);
        b[v].set(u);
        ++m;
      }
    }
}
int vis[maxn];
int res = 1e9;
void solve() {
  bitset<maxn> now;
  for (int i = 1; i <= n; ++i)
    for (int c : adj[i]) {
      now = b[i] & b[c];
      if (now.count() >= 1) {
        cout << 3;
        return;
      }
    }
  queue<int> q;
  for (int i = 1; i <= m; ++i) {
    fill_n(vis, maxn, -1);
    vis[e[i].u] = 1;
    q.push(e[i].u);
    adj[e[i].u].erase(e[i].v);
    adj[e[i].v].erase(e[i].u);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      if (vis[e[i].v] != -1) continue;
      for (int c : adj[u]) {
        if (vis[c] == -1) {
          vis[c] = vis[u] + 1;
          q.push(c);
          if (c == e[i].v) {
            res = min(res, vis[e[i].v]);
            break;
          }
        }
      }
    }
    adj[e[i].u].insert(e[i].v);
    adj[e[i].v].insert(e[i].u);
  }
  if (res == 1e9)
    cout << -1;
  else
    cout << res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  if (fopen("A"
            ".INP",
            "r")) {
    freopen(
        "A"
        ".INP",
        "r", stdin);
    freopen(
        "A"
        ".OUT",
        "w", stdout);
  }
  cin >> n;
  vector<long long> c;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    if (a[i] != 0) c.push_back(a[i]);
  }
  n = c.size();
  for (int i = 1; i <= n; ++i) a[i] = c[i - 1];
  for (int i = 0; i <= 60; ++i) {
    int cnt = 0;
    for (int j = 1; j <= n; ++j) {
      if ((1ll << i) & a[j]) cnt++;
    }
    if (cnt >= 3) return cout << 3, 0;
  }
  input();
  solve();
}
