#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n, step[maxn], ans = 0x3f3f3f3f;
long long a[maxn];
map<pair<int, int>, bool> vis;
queue<int> q;
struct edge {
  int from, to, next;
  edge() {}
  edge(int from, int to, int next) : to(to), from(from), next(next) {}
} e[205];
int head[maxn], cnt;
void add(int u, int v) {
  e[++cnt] = edge(u, v, head[u]);
  head[u] = cnt;
}
void bfs(int s, int t) {
  while (!q.empty()) q.pop();
  memset(step, 0, sizeof step);
  step[s] = 1, q.push(s);
  while (!q.empty()) {
    if (step[t]) break;
    int u = q.front();
    q.pop();
    for (int i = head[u]; i; i = e[i].next) {
      if (u == s and e[i].to == t) continue;
      if (!step[e[i].to]) step[e[i].to] = step[u] + 1, q.push(e[i].to);
    }
  }
  if (step[t]) ans = min(ans, step[t]);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int j = 0, last, tot; j <= 60; ++j) {
    last = tot = 0;
    for (int i = 1; i <= n; ++i)
      if ((a[i] >> j) & 1) {
        if (++tot == 3) {
          cout << 3 << endl;
          return 0;
        }
        if (last) {
          if (!vis[make_pair(last, i)])
            add(i, last), add(last, i);
          else
            vis[make_pair(last, i)] = true;
        } else
          last = i;
      }
  }
  for (int i = 1; i <= cnt; ++i) bfs(e[i].from, e[i].to);
  cout << (ans xor 0x3f3f3f3f ? ans : -1) << endl;
  return 0;
}
