#include <bits/stdc++.h>
using namespace std;
using lld = long long int;
void DFS(vector<vector<bool> > &graph, vector<bool> &marked, int n, int vert,
         int start, int &count) {
  marked[vert] = true;
  int V = graph.size();
  if (n == 0) {
    marked[vert] = false;
    if (graph[vert][start]) {
      count++;
      return;
    } else
      return;
  }
  for (int i = 0; i < V; i++)
    if (!marked[i] && graph[vert][i])
      DFS(graph, marked, n - 1, i, start, count);
  marked[vert] = false;
}
int countCycles(vector<vector<bool> > &graph, int n) {
  int V = graph.size();
  vector<bool> marked(V, false);
  int count = 0;
  for (int i = 0; i < V - (n - 1); i++) {
    DFS(graph, marked, n - 1, i, i, count);
    marked[i] = true;
  }
  return count / 2;
}
int main() {
  lld n;
  cin >> n;
  vector<lld> V;
  int zer = 0;
  for (int i = 0; i < n; i++) {
    lld x;
    cin >> x;
    if (x == 0) continue;
    V.push_back(x);
  }
  n = V.size();
  if (n > 256) {
    cout << 3 << endl;
  } else {
    vector<vector<bool> > G(n, vector<bool>(n, false));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (i == j)
          ;
        else if ((V[i] & V[j]) == 0)
          G[i][j] = false;
        else
          G[i][j] = true;
      }
    }
    int ans = INT_MAX;
    for (int i = 3; i <= 128; i++) {
      if (countCycles(G, i)) {
        ans = i;
        break;
      }
    }
    if (ans == INT_MAX) {
      cout << -1 << endl;
    } else {
      cout << ans << endl;
    }
  }
  return 0;
}
