#include <bits/stdc++.h>
using namespace std;
FILE* in = stdin;
FILE* out = stdout;
const int MAX = 100001;
const int INF = 1000000001;
int n;
int dist[MAX];
long long a[MAX];
int main(void) {
  fscanf(in, "%d", &n);
  for (int i = 0; i < n; i++) fscanf(in, "%lld", &a[i]);
  sort(a, a + n);
  reverse(a, a + n);
  while (n > 0 && a[n - 1] == 0) n--;
  for (int bit = 0; bit < 60; bit++) {
    int cnt = 0;
    for (int i = 0; i < n; i++)
      if (a[i] & (1LL << bit)) cnt++;
    if (cnt >= 3) {
      fprintf(out, "3\n");
      return 0;
    }
  }
  int ans = INF;
  for (int origin = 0; origin < n; origin++) {
    if (ans <= 3) break;
    memset(dist, 63, sizeof(dist));
    queue<int> q;
    q.push(origin);
    dist[origin] = 0;
    int curDist = 0;
    while (!q.empty()) {
      curDist++;
      vector<int> nnodes;
      vector<int> cnt(n, 0);
      while (!q.empty()) {
        int node = q.front();
        q.pop();
        for (int i = 0; i < n; i++) {
          if (dist[i] > INF && (a[node] & a[i])) {
            dist[i] = curDist;
            nnodes.push_back(i);
          }
          if (dist[i] == curDist && (a[node] & a[i])) cnt[i]++;
        }
      }
      for (int i = 0; i < n; i++) {
        if (cnt[i] >= 2) {
          ans = min(ans, curDist + curDist);
        }
      }
      for (int i1 = 0; i1 < (int)nnodes.size(); i1++) {
        if (ans <= 3) break;
        for (int i2 = i1 + 1; i2 < (int)nnodes.size(); i2++) {
          if (a[nnodes[i1]] & a[nnodes[i2]]) {
            ans = min(ans, curDist + curDist + 1);
          }
        }
      }
      for (int i = 0; i < (int)nnodes.size(); i++) {
        q.push(nnodes[i]);
      }
    }
  }
  fprintf(out, "%d\n", ans >= INF ? -1 : ans);
  return 0;
}
