#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5, MOD = INT_MAX;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<long long> v;
long long n;
vector<long long> adj[150];
vector<pair<long long, long long> > edge;
long long dist[150];
queue<pair<long long, long long> > q;
long long bfs(long long source, long long desti) {
  for (long long i = 0; i < n; i++) dist[i] = INT_MAX;
  while (!q.empty()) q.pop();
  q.push({source, 0});
  dist[source] = 1;
  while (!q.empty()) {
    long long u = q.front().first, d = q.front().second;
    q.pop();
    for (auto v : adj[u]) {
      if (u == source and v == desti) continue;
      if (dist[v] == INT_MAX) {
        q.push({v, d + 1});
        dist[v] = d + 1;
      }
    }
  }
  return dist[desti];
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long tmp;
  cin >> n;
  while (n--) {
    cin >> tmp;
    if (tmp != 0) v.push_back(tmp);
  }
  n = v.size();
  if (n > 122) {
    cout << 3 << endl;
    return 0;
  }
  long long ans = INT_MAX;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      if (i == j) continue;
      long long res = v[i] & v[j];
      if (res > 0) {
        adj[i].push_back(j);
        adj[j].push_back(i);
        edge.push_back({i, j});
      }
    }
  }
  for (auto e : edge) {
    long long u = e.first, v = e.second;
    long long res = bfs(u, v);
    if (res != INT_MAX) ans = min(ans, res + 1);
  }
  if (ans == INT_MAX) ans = -1;
  cout << ans << endl;
  return 0;
}
