#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int go, next;
} e[200010];
int head[100010], tot;
void add(int x, int y) {
  e[++tot].go = y;
  e[tot].next = head[x];
  head[x] = tot;
}
long long a[100010], num[65];
int vis[100010], f[100010];
long long get(int u) {
  queue<int> q;
  q.push(u);
  long long ans = 1e18;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = head[x]; i; i = e[i].next) {
      int v = e[i].go;
      if (vis[v] || v == u) {
        if (f[x] != v) ans = min((long long)vis[x] + vis[v] + 1, ans);
        continue;
      }
      if (v != u) q.push(v), vis[v] = vis[x] + 1, f[v] = x;
    }
  }
  return ans;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    for (int j = 62; j >= 0; j--) {
      if (a[i] & (1LL << j)) num[j]++;
    }
  }
  for (int i = 0; i < 63; i++)
    if (num[i] >= 3) {
      puts("3");
      return 0;
    }
  sort(a + 1, a + n + 1, greater<long long>());
  int cnt = n;
  for (int i = 1; i <= n; i++) {
    if (a[i] == 0) {
      cnt = i - 1;
      break;
    }
    for (int j = 1; j < i; j++) {
      if (a[i] & a[j]) add(i, j), add(j, i);
    }
  }
  long long ans = 1e18;
  for (int i = 1; i <= cnt; i++) {
    memset(vis, 0, sizeof(int) * (cnt + 1));
    memset(f, 0, sizeof(int) * (cnt + 1));
    ans = min(ans, get(i));
  }
  if (ans > 1e17)
    puts("-1");
  else
    printf("%lld", ans);
  return 0;
}
