#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
struct Edge {
  int u;
  int v;
  int weight;
};
class Graph {
  int V;
  list<pair<int, int> >* adj;
  vector<Edge> edge;

 public:
  Graph(int V) {
    this->V = V;
    adj = new list<pair<int, int> >[V];
  }
  void addEdge(int u, int v, int w);
  void removeEdge(int u, int v, int w);
  int ShortestPath(int u, int v);
  void RemoveEdge(int u, int v);
  int FindMinimumCycle();
};
void Graph ::addEdge(int u, int v, int w) {
  adj[u].push_back(make_pair(v, w));
  adj[v].push_back(make_pair(u, w));
  Edge e{u, v, w};
  edge.push_back(e);
}
void Graph ::removeEdge(int u, int v, int w) {
  adj[u].remove(make_pair(v, w));
  adj[v].remove(make_pair(u, w));
}
int Graph ::ShortestPath(int u, int v) {
  set<pair<int, int> > setds;
  vector<int> dist(V, (int)1e9);
  setds.insert(make_pair(0, u));
  dist[u] = 0;
  while (!setds.empty()) {
    pair<int, int> tmp = *(setds.begin());
    setds.erase(setds.begin());
    int u = tmp.second;
    list<pair<int, int> >::iterator i;
    for (i = adj[u].begin(); i != adj[u].end(); ++i) {
      int v = (*i).first;
      int weight = (*i).second;
      if (dist[v] > dist[u] + weight) {
        if (dist[v] != (int)1e9) setds.erase(setds.find(make_pair(dist[v], v)));
        dist[v] = dist[u] + weight;
        setds.insert(make_pair(dist[v], v));
      }
    }
  }
  return dist[v];
}
int Graph ::FindMinimumCycle() {
  int min_cycle = 300;
  int E = edge.size();
  for (int i = 0; i < E; i++) {
    Edge e = edge[i];
    removeEdge(e.u, e.v, e.weight);
    int vistance = ShortestPath(e.u, e.v);
    min_cycle = min(min_cycle, vistance + e.weight);
    addEdge(e.u, e.v, e.weight);
  }
  return min_cycle;
}
int main(int argc, char const* argv[]) {
  cin.sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int zercounter = 0;
  vector<long long> vals(n);
  bool chk = false;
  for (int i = 0; i < n; i++) {
    cin >> vals[i];
    if (vals[i] == 0) zercounter++;
  }
  n = vals.size();
  if (chk) {
    cout << "NUMBER OF ZEROES IS EQUAL TO " << zercounter << endl;
    cout << "NUMBER OF OTHER NUMBERS IS EQUAL TO " << n - zercounter << endl;
    for (int i = 1; i < n; i++) {
      if (vals[i] == vals[i - 1]) continue;
      cout << vals[i] << " ";
    }
    return 0;
  }
  map<int, vector<int> > b;
  for (int i = 0; i < n; i++) {
    if (vals[i] == 0) continue;
    for (int j = 63; j >= 0; j--) {
      if (vals[i] & 1ll << j) {
        b[j].push_back(i);
      }
    }
  }
  vector<set<int> > ad(n);
  Graph g(n);
  bool oth = false;
  for (auto& x : b) {
    if (x.second.size() > 2) {
      cout << 3;
      return 0;
    } else if (x.second.size() == 1)
      continue;
    else if (x.second.size() == 2) {
      ad[min(x.second[1], x.second[0])].insert(max(x.second[0], x.second[1]));
      oth = true;
    }
  }
  if (!oth) {
    cout << -1;
    return 0;
  }
  vector<vector<int> > adj(n);
  for (int i = 0; i < n; i++) {
    for (auto& x : ad[i]) {
      g.addEdge(i, x, 1);
    }
  }
  int ret = g.FindMinimumCycle();
  if (ret >= 150) ret = -1;
  cout << ret << endl;
  return 0;
}
