#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300005;
const int INF = 1e9;
int n;
vector<int> bs[70];
vector<unsigned long long> A;
int G[130][130];
int dis[130];
int bfs(int sti, int edi) {
  for (int i = 0; i < n; i++) dis[i] = INF;
  dis[sti] = 0;
  queue<int> q;
  q.push(sti);
  while (!q.empty()) {
    int ci = q.front();
    q.pop();
    for (int i = 0; i < n; i++) {
      if (G[ci][i]) {
        if (dis[i] > dis[ci] + 1) {
          q.push(i);
          dis[i] = dis[ci] + 1;
        }
      }
    }
  }
  return dis[edi];
}
int calc(int i1, int i2) {
  int ret = bfs(i1, i2);
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    unsigned long long x;
    scanf("%llu", &x);
    if (x) A.push_back(x);
  }
  n = A.size();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 64; j++) {
      if (((unsigned long long)1 << j) & A[i]) {
        bs[j].push_back(i);
      }
    }
  }
  for (int i = 0; i < 64; i++) {
    if (bs[i].size() >= 3) {
      puts("3");
      return 0;
    }
  }
  for (int i = 0; i < 64; i++) {
    for (int j = 0; j < bs[i].size(); j++) {
      for (int k = j + 1; k < bs[i].size(); k++) {
        int u = bs[i][j];
        int v = bs[i][k];
        G[u][v] = G[v][u] = 1;
      }
    }
  }
  int ans = INF;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (G[i][j]) {
        G[i][j] = G[j][i] = 0;
        int ret = calc(i, j);
        ans = min(ans, ret + 1);
        G[i][j] = G[j][i] = 1;
      }
    }
  }
  if (ans == INF) {
    puts("-1");
  } else {
    printf("%d", ans);
  }
  return 0;
}
