#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  t = 1;
  for (long long test = 1; test <= t; test++) {
    long long n;
    cin >> n;
    vector<long long> a;
    for (long long i = 0; i <= n - 1; i++) {
      long long x;
      cin >> x;
      if (x != 0) a.push_back(x);
    }
    long long bits[61] = {0};
    n = a.size();
    for (long long i = 0; i <= n - 1; i++) {
      long long temp = a[i];
      long long j = 0;
      while (temp > 0) {
        if (temp & 1) bits[j]++;
        temp = temp >> 1;
        j++;
      }
    }
    for (long long i = 0; i <= 60; i++)
      if (bits[i] >= 3) {
        cout << 3;
        exit(0);
      }
    long long cyclec = -1;
    vector<vector<long long>> adj(n);
    for (long long i = 0; i < n; i++)
      for (long long j = i + 1; j < n; j++)
        if ((a[i] & a[j]) != 0) {
          adj[i].push_back(j);
          adj[j].push_back(i);
        }
    for (long long i = 0; i <= n - 1; i++)
      if (adj[i].size() != 0) {
        vector<long long> dis(n, -1);
        vector<long long> par(n, -1);
        queue<long long> q;
        q.push(i);
        dis[i] = 0;
        par[i] = -1;
        while (!q.empty()) {
          auto x = q.front();
          q.pop();
          for (auto y : adj[x])
            if (dis[y] == -1) {
              dis[y] = 1 + dis[x];
              par[y] = x;
              q.push(y);
            } else if (y != par[x]) {
              if (cyclec == -1)
                cyclec = (dis[y] + dis[x] + 1);
              else
                cyclec = min(cyclec, dis[y] + dis[x] + 1);
            }
        }
      }
    cout << cyclec;
  }
  return 0;
}
