#include <bits/stdc++.h>
using namespace std;
long long d[210][210], m[210][210];
long long a[100010];
vector<long long> Lis[100];
int main() {
  ios::sync_with_stdio(false);
  long long i, n, ans = (1ll << 60), t, j, k, tot = 0;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[++tot];
    if (a[tot] == 0) tot--;
  }
  n = tot;
  if (n > 200) {
    cout << 3;
    return 0;
  }
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++) d[i][j] = m[i][j] = 0x3f3f3f3f;
  for (i = 1; i <= n; i++)
    for (j = i + 1; j <= n; j++)
      if (a[i] & a[j]) d[i][j] = d[j][i] = m[i][j] = m[j][i] = 1;
  for (k = 1; k <= n; k++) {
    for (i = 1; i < k; i++)
      for (j = i + 1; j < k; j++)
        if (d[i][j] + m[i][k] + m[k][j] < ans and
            d[i][j] + m[i][k] + m[k][j] > 2)
          ans = d[i][j] + m[i][k] + m[k][j];
    for (i = 1; i <= n; i++)
      for (j = 1; j <= n; j++)
        if (d[i][k] + d[k][j] < d[i][j]) d[i][j] = d[i][k] + d[k][j];
  }
  if (ans < 0x3f3f3f3f)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
