#include <bits/stdc++.h>
using namespace std;
vector<long long> a;
int n;
vector<vector<long long>> v;
vector<vector<int>> cou;
vector<set<int>> g;
vector<long long> f(long long x, int num) {
  long long y = x;
  vector<long long> ans = {};
  for (int i = 0; i < 70; i++) {
    if (y % 2 == 1) cou[i].push_back(num);
    ans.push_back(y % 2);
    y /= 2;
  }
  return ans;
}
int bfs(int s) {
  int min_c = 1e9;
  vector<set<int>> temp = g;
  queue<int> q;
  q.push(s);
  vector<bool> used;
  used.resize(n);
  vector<int> d;
  d.resize(n);
  for (int i = 0; i < used.size(); i++) {
    used[i] = false;
    d[i] = 0;
  }
  used[s] = true;
  int dep = 0;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (auto to : temp[v]) {
      if (!used[to]) {
        used[to] = true;
        q.push(to);
        temp[to].erase(v);
        d[to] = d[v] + 1;
      } else {
        min_c = min(min_c, d[to] + d[v] + 1);
      }
    }
  }
  return min_c;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  a.resize(n);
  cou.resize(100);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    v.push_back(f(a[i], i));
  }
  for (int i = 0; i < cou.size(); i++) {
    if (cou[i].size() >= 3) {
      cout << 3 << endl;
      return 0;
    }
  }
  g.resize(n);
  for (int i = 0; i < cou.size(); i++) {
    for (int j = 0; j < cou[i].size(); j++) {
      for (int k = j + 1; k < cou[i].size(); k++) {
        g[cou[i][j]].insert(cou[i][k]);
        g[cou[i][k]].insert(cou[i][j]);
      }
    }
  }
  int ans = 1e9;
  for (int i = 0; i < n; i++) {
    if (g[i].size() > 0) {
      ans = min(ans, bfs(i));
    }
  }
  if (ans == 1e9)
    cout << -1;
  else
    cout << ans;
  return 0;
}
