#include <bits/stdc++.h>
using namespace std;
int bfs(const vector<vector<int> >& g, int idx) {
  int n = g.size();
  vector<int> level(n, -1);
  queue<int> q;
  vector<int> parent(n, -1);
  q.push(idx);
  level[idx] = 0;
  int ans = 1e9;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (auto to : g[v]) {
      if (level[to] == -1) {
        q.push(to);
        parent[to] = v;
        level[to] = level[v] + 1;
        continue;
      }
      if (parent[v] != to) {
        ans = min(ans, level[to] + level[v] + 1);
      }
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<int> cnt(61);
  for (int i = 0; i < n; ++i) {
    long long x = a[i];
    int _cnt = 0;
    while (x) {
      if (x & 1) {
        ++cnt[_cnt];
      }
      x >>= 1;
      ++_cnt;
    }
  }
  vector<int> indices;
  for (int i = 0; i < n; ++i) {
    if (a[i]) indices.push_back(i);
  }
  for (int i = 0; i < 61; ++i) {
    if (cnt[i] >= 3) {
      cout << 3;
      return 0;
    }
  }
  vector<vector<int> > g(n);
  for (auto x : indices) {
    for (auto y : indices) {
      if (x >= y) continue;
      if (a[x] & a[y]) {
        g[x].push_back(y);
        g[y].push_back(x);
      }
    }
  }
  int ans = 1e9;
  for (int i = 0; i < n; ++i) {
    if (!a[i]) {
      continue;
    }
    ans = min(ans, bfs(g, i));
  }
  if (ans == 1e9) {
    cout << -1;
  } else {
    cout << ans;
  }
  return 0;
}
