#include <bits/stdc++.h>
using namespace std;
const long long int inf = 0x3f3f3f3f3f3f3f3fll;
const int INF = (int)1e9 + 43;
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
vector<int> adj[100005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int n;
  cin >> n;
  int i, j;
  long long int a[n + 1];
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  set<int> s;
  for (i = 0; i < 61; i++) {
    int fir = -1, sec = -1;
    for (j = 1; j <= n; j++) {
      if ((1ll << i) & a[j]) {
        if (fir == -1) {
          fir = j;
        } else if (sec == -1) {
          sec = j;
        } else {
          cout << 3 << "\n";
          return 0;
        }
      }
    }
    if (sec != -1) {
      s.insert(fir);
      s.insert(sec);
      adj[fir].push_back(sec);
      adj[sec].push_back(fir);
    }
  }
  int ans = INF;
  for (auto i : s) {
    vector<int> dis(n + 1, INF);
    vector<int> par(n + 1, -1);
    dis[i] = 0;
    queue<int> q;
    q.push(i);
    while (!q.empty()) {
      int x = q.front();
      q.pop();
      for (int j : adj[x]) {
        if (dis[j] == INF) {
          q.push(j);
          dis[j] = dis[x] + 1;
          par[j] = x;
        } else if (par[j] != x && par[x] != j) {
          ans = min(ans, dis[x] + dis[j] + 1);
        }
      }
    }
  }
  if (ans == INF) {
    ans = -1;
  }
  cout << ans << "\n";
}
