#include <bits/stdc++.h>
using namespace std;
struct QVertex {
  int u, v, dist;
  QVertex() { u = v = dist = 0; }
  QVertex(int uu, int vv, int ddist) {
    u = uu;
    v = vv;
    dist = ddist;
  }
};
long long a[130];
int dist[130][130];
bool vis[130][130];
vector<int> conn[130];
int N;
int ans;
queue<QVertex> q;
QVertex cur;
int main() {
  cin >> N;
  int ans = 140;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      --i;
      --N;
    }
    if (i > 125) {
      cout << 3 << endl;
      return 0;
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (a[i] & a[j]) {
        conn[i].push_back(j);
        conn[j].push_back(i);
      }
    }
  }
  ans = 140;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      for (int k = 0; k < N; k++) {
        vis[j][k] = false;
      }
    }
    while (!q.empty()) {
      q.pop();
    }
    for (int j = 0; j < conn[i].size(); j++) {
      q.push(QVertex(i, conn[i][j], 1));
    }
    while (!q.empty()) {
      cur = q.front();
      q.pop();
      if (!vis[cur.u][cur.v]) {
        vis[cur.u][cur.v] = true;
      }
      if (cur.v == i) {
        ans = min(ans, cur.dist);
        break;
      }
      for (int j = 0; j < conn[cur.v].size(); j++) {
        if (conn[cur.v][j] != cur.u) {
          q.push(QVertex(cur.v, conn[cur.v][j], cur.dist + 1));
        }
      }
    }
  }
  if (ans == 140)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
