#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:2000000")
#pragma comment(linker, "/HEAP:2000000")
using namespace std;
void print_width(long long x) {
  std::cout << std::fixed;
  std::cout << std::setprecision(x);
}
long long power(long long x, long long y, long long p = 1000000007) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
void printArr(long long a[], long long n) {
  for (long long i = 0; i < n; i++) cout << a[i] << " ";
  cout << '\n';
}
void printVector(std::vector<long long> v) {
  for (long long i = 0; i < v.size(); i++) cout << v[i] << " ";
  cout << '\n';
}
void printVectorPair(std::vector<pair<long long, long long>> v) {
  for (long long i = 0; i < v.size(); i++)
    cout << v[i].first << " " << v[i].second << '\n';
  ;
  cout << '\n';
}
void initialize(long long arr[], long long n) {
  for (long long i = 0; i <= n; i++) arr[i] = i;
}
long long root(long long arr[], long long i) {
  while (arr[i] != i) {
    arr[i] = arr[arr[i]];
    i = arr[i];
  }
  return i;
}
void Union(long long arr[], long long a, long long b) {
  long long root_a = root(arr, a);
  long long root_b = root(arr, b);
  arr[root_a] = root_b;
}
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long power_wm(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
std::vector<long long> vsum(std::vector<long long> a) {
  std::vector<long long> s(a.size());
  s[0] = a[0];
  for (long long i = 1; i <= a.size() - 1; i++) {
    s[i] = s[i - 1] + a[i];
  }
  return s;
}
void time() {}
long long sti(string s) {
  long long ans = 0;
  long long p = 1;
  for (long long i = s.size() - 1; i >= 0; i--) {
    ans = (ans + ((long long)(s[i] - '0') * p) % 1000000007) % 1000000007;
    p = (p * 10) % 1000000007;
  }
  return ans;
}
long long bfs(long long x, long long y, vector<vector<long long>> &g) {
  std::vector<long long> vis(100001, 0);
  vis[x] = 1;
  queue<long long> q;
  q.push(x);
  std::vector<long long> level(100001, (long long)1e18);
  level[x] = 0;
  while (!q.empty()) {
    long long p = q.front();
    q.pop();
    for (long long i = 0; i < g[p].size(); i++) {
      long long p2 = g[p][i];
      if (vis[p2] == 0) {
        if (x == p and y == p2) {
          continue;
        } else {
          q.push(p2);
          vis[p2] = 1;
          level[p2] = level[p] + 1;
        }
      }
    }
  }
  return level[y];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  std::vector<long long> a(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long bit = 1;
  for (long long i = 0; i < 63; i++) {
    long long c = 0;
    for (long long j = 0; j < n; j++)
      if ((a[j] & bit) > 0) c++;
    if (c >= 3) {
      cout << "3";
      return 0;
    }
    bit = bit << 1;
  }
  vector<vector<long long>> g(n + 1, vector<long long>(0));
  ;
  set<pair<long long, long long>> edge;
  bit = 1;
  for (long long i = 0; i < 63; i++) {
    long long c = 0;
    long long p1 = -1, p2 = -1;
    for (long long j = 0; j < n; j++)
      if ((a[j] & bit) > 0) {
        c++;
        if (p1 == -1) {
          p1 = j;
        } else {
          p2 = j;
        }
      }
    if (c == 2) {
      edge.insert(make_pair(p1, p2));
      edge.insert(make_pair(p2, p1));
      g[p1].push_back(p2);
      g[p2].push_back(p1);
    }
    bit = bit << 1;
  }
  long long ans = (long long)1e18;
  for (auto x : edge) {
    long long a = x.first;
    long long b = x.second;
    long long le = bfs(a, b, g);
    ans = min(ans, le + 1);
  }
  if (ans < (long long)1e18) {
    cout << ans;
  } else {
    cout << -1;
  }
  return 0;
}
