#include <bits/stdc++.h>
using namespace std;
template <typename T>
void gi(T &angka) {
  angka = 0;
  char input = getchar();
  T kali = 1;
  while (!(48 <= input && input <= 57)) {
    if (input == '-') kali = -1;
    input = getchar();
  }
  while (48 <= input && input <= 57)
    angka = (angka << 3) + (angka << 1) + input - 48, input = getchar();
  angka *= kali;
}
template <typename T1, typename T2>
void gi(T1 &angka1, T2 &angka2) {
  gi(angka1);
  gi(angka2);
}
const int MAXN = 100000;
int n;
long long arr[MAXN + 5];
void readInput() {
  gi(n);
  for (int i = 0; i < n; ++i) {
    gi(arr[i]);
    if (arr[i] == 0) {
      n--;
      i--;
    }
  }
}
bool cliqueCheck() {
  for (int i = 0; i < 60; ++i) {
    int total = 0;
    for (int j = 0; j < n; ++j) {
      if (arr[j] & (1LL << i)) {
        total++;
      }
    }
    if (total >= 3) {
      return true;
    }
  }
  return false;
}
vector<int> node[MAXN + 5];
void buildGraph() {
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (arr[i] & arr[j]) {
        node[i].push_back(j);
        node[j].push_back(i);
      } else {
      }
    }
  }
}
const int INF = 1000;
int dist[MAXN + 5], par[MAXN + 5];
int bfs(int s) {
  for (int i = 0; i < n; ++i) {
    dist[i] = INF;
    par[i] = -1;
  }
  queue<int> q;
  q.push(s);
  dist[s] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto v : node[u]) {
      if (v == par[u]) {
        continue;
      }
      if (dist[v] == INF) {
        dist[v] = dist[u] + 1;
        par[v] = u;
        q.push(v);
      } else {
        return dist[v] + dist[u] + 1;
      }
    }
  }
  return INF;
}
void solve() {
  int ans = INF;
  if (cliqueCheck()) {
    ans = 3;
  } else if (n <= 200) {
    buildGraph();
    for (int i = 0; i < n; ++i) {
      ans = min(ans, bfs(i));
    }
  }
  if (ans == INF) {
    ans = -1;
  }
  printf("%d\n", ans);
}
int main() {
  int tc;
  tc = 1;
  while (tc--) {
    readInput();
    solve();
  }
}
