#include <bits/stdc++.h>
using namespace std;
const int N = 200;
int g[N][N], d[N][N];
long long a[N];
int n, m, cnt;
signed main() {
  scanf("%d", &n);
  memset(g, 0x3f, sizeof g);
  for (int i = 1; i <= n; ++i) {
    if (i >= 128) break;
    scanf("%lld", &a[i]);
    if (!a[i]) --i, --n;
  }
  if (n >= 128) {
    puts("3");
    return 0;
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if ((a[i] & a[j]) && i != j)
        g[i][j] = 1;
      else
        g[i][j] = 0x3f3f3f3f;
  memcpy(d, g, sizeof g);
  long long res = 0x3f3f3f3f;
  for (int k = 1; k <= n; ++k) {
    for (int i = 1; i < k; ++i)
      for (int j = i + 1; j < k; ++j)
        if ((long long)d[i][j] + g[i][k] + g[k][j] < res)
          res = d[i][j] + g[i][k] + g[k][j];
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= n; ++j)
        if (d[i][j] > d[i][k] + d[k][j]) d[i][j] = d[i][k] + d[k][j];
  }
  if (res != 0x3f3f3f3f)
    printf("%lld ", res);
  else
    puts("-1");
  return 0;
}
