#include <bits/stdc++.h>
using namespace std;
long long int em(long long int x, long long int Mod, long long int n) {
  if (n == 0)
    return 1ll;
  else if (n % 2 == 0)
    return em((x % Mod * x % Mod) % Mod, Mod, n / 2) % Mod;
  else
    return (x % Mod * em((x % Mod * x % Mod) % Mod, Mod, (n - 1) / 2)) % Mod;
}
long long int cou[64];
vector<long long int> nums[64];
vector<long long int> gr[2000009];
long long int dis[2000009];
long long int vis[2000009], ans;
void bfs(long long int x, long long int se) {
  long long int i, j, k;
  queue<pair<long long int, long long int> > q;
  q.push({0, x});
  while (!q.empty()) {
    pair<long long int, long long int> u = q.front();
    q.pop();
    vis[u.second] = 1;
    for (long long int y : gr[u.second]) {
      if (vis[y] || (u.second == x && y == se)) continue;
      if (dis[y] > dis[u.second] + 1) {
        dis[y] = dis[u.second] + 1;
        q.push({dis[y], y});
      }
    }
  }
}
int32_t main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, i, j, k, l;
  cin >> n;
  long long int arr[n + 1];
  long long int flag = 0;
  ans = 1e18;
  for (long long int i = (long long int)1; i < (long long int)n + 1; i++) {
    cin >> arr[i];
    for (j = 0; j < 64; j++) {
      if (((arr[i] >> j) & 1)) {
        cou[j]++;
        if (cou[j] > 2) {
          ans = 3;
          flag = 1;
          break;
        }
        nums[j].push_back(i);
      }
    }
    if (flag) break;
  }
  if (flag)
    cout << ans << "\n";
  else {
    vector<long long int> avail;
    vector<pair<long long int, long long int> > edges;
    for (i = 0; i < 64; i++) {
      if (nums[i].size() >= 2) {
        gr[nums[i][0]].push_back(nums[i][1]);
        gr[nums[i][1]].push_back(nums[i][0]);
        avail.push_back(nums[i][0]);
        avail.push_back(nums[i][1]);
        edges.push_back({nums[i][0], nums[i][1]});
      }
    }
    for (pair<long long int, long long int> y : edges) {
      for (long long int y : avail) {
        dis[y] = 1e18;
        vis[y] = 0;
      }
      dis[y.first] = 0;
      bfs(y.first, y.second);
      if (dis[y.second] != 1e18) ans = min(ans, 1 + dis[y.second]);
    }
    if (ans == 1e18)
      cout << "-1\n";
    else
      cout << ans << "\n";
  }
}
