#include <bits/stdc++.h>
using namespace std;
vector<pair<long long int, long long int> > adj[130];
vector<int> vis(130, 0);
vector<long long int> dist(130, 1e18), par(130, 0);
priority_queue<pair<long long int, long long int>,
               vector<pair<long long int, long long int> >,
               greater<pair<long long int, long long int> > >
    pq;
void dijkstra(long long int s) {
  dist[s] = 0;
  par[s] = s;
  pq.push({dist[s], s});
  long long int up;
  while (!pq.empty()) {
    up = pq.top().second;
    pq.pop();
    if (vis[up] == 1) continue;
    vis[up] = 1;
    for (long long int i = 0; i < adj[up].size(); i++) {
      if (dist[up] + adj[up][i].second < dist[adj[up][i].first]) {
        dist[adj[up][i].first] = dist[up] + adj[up][i].second;
        pq.push({dist[adj[up][i].first], adj[up][i].first});
        par[adj[up][i].first] = up;
      }
    }
  }
  return;
}
int main() {
  vector<long long int> po(61, 1);
  for (long long int i = 1; i <= 60; i++) po[i] = po[i - 1] * 2;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n;
  cin >> n;
  vector<long long int> v(n + 1), cou(61, 0), couadj[61];
  for (long long int i = 1; i <= n; i++) cin >> v[i];
  for (long long int j = 60; j >= 0; j--)
    for (long long int i = 1; i <= n; i++) {
      if (v[i] >= po[j]) {
        cou[j]++;
        v[i] = v[i] % po[j];
        couadj[j].push_back(i);
      }
    }
  long long int big = *max_element((cou).begin(), (cou).end());
  if (big >= 3) {
    cout << "3" << '\n';
    return 0;
  }
  map<long long int, long long int> has;
  map<pair<long long int, long long int>, long long int> pre;
  vector<vector<long long int> > edg;
  long long int temp = 1;
  for (long long int i = 0; i <= 60; i++) {
    if (couadj[i].size() == 2) {
      if (has[couadj[i][0]] == 0) {
        has[couadj[i][0]] = temp;
        temp++;
      }
      if (has[couadj[i][1]] == 0) {
        has[couadj[i][1]] = temp;
        temp++;
      }
      long long int x = has[couadj[i][0]];
      long long int y = has[couadj[i][1]];
      if (!pre[make_pair(max(x, y), min(x, y))]) {
        pre[make_pair(max(x, y), min(x, y))] = 1;
        vector<long long int> temp(3);
        temp[0] = x;
        temp[1] = y;
        temp[2] = 1;
        edg.push_back(temp);
      }
    }
  }
  long long int ans = 1e18;
  long long int m = edg.size();
  for (long long int j = 0; j < m; j++) {
    long long int sour = edg[j][0], dest = edg[j][1];
    for (long long int k = 0; k <= 129; k++) {
      adj[k].clear();
      vis[k] = 0;
      dist[k] = 1e18;
    }
    for (long long int i = 0; i < m; i++) {
      if (i == j) continue;
      adj[edg[i][0]].push_back({edg[i][1], edg[i][2]});
      adj[edg[i][1]].push_back({edg[i][0], edg[i][2]});
    }
    dijkstra(sour);
    ans = min(ans, dist[dest] + edg[j][2]);
  }
  if (ans == 1e18)
    cout << "-1" << '\n';
  else
    cout << ans << '\n';
  return 0;
}
