#include <bits/stdc++.h>
using namespace std;
int cnt = 0;
const int NMAX = 100005;
const int NNMAX = 200;
const int INF = 1000000009;
const int ln = 64;
long long v[NMAX];
int m[NMAX];
vector<int> bits[NNMAX];
int f[100005];
int dist[NNMAX][NNMAX];
int d[NMAX];
int t[NMAX];
int n;
bool ok = true;
inline void learntoread() {
  cin >> n;
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    cin >> v[++cnt];
    if (v[cnt] == 0)
      cnt--;
    else
      ok = false;
  }
  n = cnt;
}
inline void foreplay() {
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < ln; j++)
      if ((1ll << j) & v[i]) bits[j].push_back(i);
  }
  for (int i = 0; i < ln; i++)
    if (bits[i].size() == 2) {
      int a = bits[i][0];
      int b = bits[i][1];
      if (f[a] == 0) {
        m[a] = cnt++;
        f[a] = 1;
      }
      if (f[b] == 0) {
        m[b] = cnt++;
        f[b] = 1;
      }
      a = m[a];
      b = m[b];
      dist[a][b] = 1;
      dist[b][a] = 1;
    }
}
inline int breadfirstsearchafter(int nod) {
  memset(t, -1, sizeof(t));
  for (int i = 0; i < ln; i++) d[i] = INF;
  d[nod] = 0;
  queue<int> q;
  q.push(nod);
  while (!q.empty()) {
    int temp = q.front();
    q.pop();
    for (int i = 0; i < ln; i++)
      if (dist[temp][i] == 1 && temp != i) {
        if (t[temp] == i) continue;
        if (t[i] == -1) {
          q.push(i);
          t[i] = temp;
          d[i] = d[temp] + 1;
        } else
          return d[i] + d[temp] + 1;
      }
  }
  return INF;
}
inline void ifonlyicoulddisolvemyproblems() {
  if (ok == true) {
    cout << "-1\n";
    return;
  }
  for (int i = 0; i < ln; i++)
    if (bits[i].size() > 2) {
      cout << 3 << "\n";
      return;
    }
  int mi = INF;
  for (int i = 1; i <= n; i++) mi = min(mi, breadfirstsearchafter(m[i]));
  if (mi == INF)
    cout << "-1\n";
  else
    cout << mi << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  learntoread();
  foreplay();
  ifonlyicoulddisolvemyproblems();
  return 0;
}
