#include <bits/stdc++.h>
using namespace std;
class Debugger {
 public:
  Debugger(const std::string& _separator = " | ")
      : first(true), separator(_separator) {}
  template <typename ObjectType>
  Debugger& operator,(const ObjectType& v) {
    if (!first) std::cerr << separator;
    std::cerr << v;
    first = false;
    return *this;
  }
  ~Debugger() { std::cerr << std::endl; }

 private:
  bool first;
  std::string separator;
};
const long long N = 1e5 + 5;
long long n;
std::vector<long long> g[N];
long long bfs(long long u, long long v) {
  std::vector<long long> visit(n, 0);
  queue<pair<long long, long long>> q;
  visit[u] = true;
  for (long long i = 0; i < g[u].size(); ++i) {
    if (g[u][i] == v) continue;
    q.push({g[u][i], 1});
  }
  while (!q.empty()) {
    pair<long long, long long> cur = q.front();
    q.pop();
    if (cur.first == v) {
      return cur.second + 1;
    }
    if (visit[cur.first]) continue;
    visit[cur.first] = true;
    for (long long i = 0; i < g[cur.first].size(); ++i) {
      if (visit[g[cur.first][i]]) continue;
      q.push({g[cur.first][i], cur.second + 1});
    }
  }
  return INT_MAX;
}
void solve() {
  cin >> n;
  std::vector<long long> v(n);
  for (long long i = 0; i < n; ++i) {
    cin >> v[i];
  }
  std::vector<long long> temp;
  for (long long i = 0; i < 62; ++i) {
    temp.clear();
    for (long long j = 0; j < n; ++j) {
      if (v[j] & (1LL << i)) {
        temp.push_back(j);
      }
    }
    if (temp.size() >= 3) {
      cout << 3 << "\n";
      return;
    }
    if (temp.size() == 2) {
      g[temp[0]].push_back(temp[1]);
      g[temp[1]].push_back(temp[0]);
    }
  }
  long long ans = INT_MAX;
  std::vector<long long> visit(n, 0);
  for (long long i = 0; i < n; ++i) {
    visit.resize(n, 0);
    if (g[i].size()) {
      for (long long j = 0; j < g[i].size(); ++j) {
        if (i < g[i][j])
          if (visit[g[i][j]]) continue;
        visit[g[i][j]] = true;
        ans = min(ans, bfs(i, g[i][j]));
      }
    }
  }
  if (ans == INT_MAX) {
    cout << -1 << "\n";
  } else {
    cout << ans << "\n";
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0),
      cout << fixed << setprecision(10);
  ;
  long long T;
  T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
