#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long> d(n);
  for (int i = 0; i < n; i++) cin >> d[i];
  sort(d.rbegin(), d.rend());
  while (n && d[n - 1] == 0) n--;
  if (n > 120) return cout << 3 << endl, 0;
  vector<set<int>> g(n);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (i != j && d[i] & d[j]) g[i].insert(j);
  long long ans = LLONG_MAX;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++)
      if (g[i].count(j)) {
        g[i].erase(j);
        queue<int> q;
        q.push(i);
        vector<long long> dist(n, INT_MAX);
        vector<bool> used(n, false);
        used[i] = true;
        dist[i] = 0;
        while (!q.empty()) {
          int v = q.front();
          q.pop();
          if (v == j) break;
          for (int k : g[v]) {
            if (!used[k]) {
              dist[k] = dist[v] + 1;
              q.push(k);
              used[k] = true;
            }
          }
        }
        if (dist[j] != INT_MAX) ans = min(ans, 1 + dist[j]);
        g[i].insert(j);
      }
  }
  cout << (ans == LLONG_MAX ? -1 : ans) << endl;
  return 0;
}
