#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int cnt = 1, head[maxn] = {0};
int maxx = maxn;
long long b[maxn], step[maxn] = {0};
bool vis[500];
struct Edge {
  long long to, next, w;
} edge[maxn];
void add(int u, int v) {
  edge[cnt].next = head[u];
  edge[cnt].to = v;
  head[u] = cnt++;
}
vector<int> vt[100];
int bfs(int u, int y) {
  queue<int> que;
  memset(vis, 0, sizeof(vis));
  vis[u] = 1;
  step[u] = 1;
  que.push(u);
  while (!que.empty()) {
    int q = que.front();
    que.pop();
    for (int i = head[q]; i; i = edge[i].next) {
      int v = edge[i].to;
      if (v == y) {
        if (q != u)
          return step[q] + 1;
        else
          continue;
      }
      if (!vis[v]) {
        step[v] = step[q] + 1;
        vis[v] = 1;
        que.push(v);
      }
    }
  }
  return -1;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &b[i]);
    long long c = b[i];
    int x = 0;
    while (c) {
      if (c % 2 == 1) vt[x].push_back(i + 1);
      if (vt[x].size() > 2) {
        printf("3\n");
        return 0;
      }
      x++;
      c >>= 1;
    }
  }
  for (int i = 0; i < 100; i++) {
    if (vt[i].size() == 2) {
      add(vt[i][0], vt[i][1]);
      add(vt[i][1], vt[i][0]);
    }
  }
  for (int i = 0; i < 100; i++) {
    if (vt[i].size() == 2) {
      int x = vt[i][0], y = vt[i][1];
      int h = bfs(x, y);
      if (h != -1) {
        maxx = min(maxx, h);
      }
    }
  }
  if (maxx == maxn)
    printf("-1\n");
  else
    printf("%d\n", maxx);
}
