#include <bits/stdc++.h>
using namespace std;
inline void print(int n) {
  if (n == 0) {
    putchar('0');
    putchar('\n');
  } else if (n == -1) {
    putchar('-');
    putchar('1');
    putchar('\n');
  } else {
    char buf[11];
    buf[10] = '\n';
    int i = 9;
    while (n) {
      buf[i--] = n % 10 + '0';
      n /= 10;
    }
    while (buf[i] != '\n') putchar(buf[++i]);
  }
}
int read() {
  int cc = getc(stdin);
  for (; cc < '0' || cc > '9';) cc = getc(stdin);
  int ret = 0;
  for (; cc >= '0' && cc <= '9';) {
    ret = ret * 10 + cc - '0';
    cc = getc(stdin);
  }
  return ret;
}
long long power(long long num, long long g) {
  if (g == 0) return 1;
  if (g % 2 == 1) return (num * power((num * num), g / 2));
  return power((num * num), g / 2);
}
long long a[100005];
vector<long long> vec1[100005];
int visit[3600];
void solve(long long n) {
  vector<long long> vec[60];
  long long g = 1;
  for (int i = 0; i < 60; i++) {
    for (int j = 0; j < n; j++) {
      if (a[j] & g) vec[i].push_back(j);
    }
    if (vec[i].size() >= 3) {
      cout << "3\n";
      return;
    }
    g *= 2;
  }
  map<pair<int, int>, int> mp1;
  for (int i = 0; i < 60; i++) {
    if (vec[i].size() >= 3) {
      cout << "3\n";
      return;
    }
    for (int j = 0; j < vec[i].size(); j++) {
      if (j == 0) continue;
      if (mp1.find(make_pair(vec[i][j - 1], vec[i][j])) != mp1.end())
        continue;
      else
        mp1[make_pair(vec[i][j - 1], vec[i][j])] == 1,
            mp1[make_pair(vec[i][j], vec[i][j - 1])] == 1;
      vec1[vec[i][j]].push_back(vec[i][j - 1]);
      vec1[vec[i][j - 1]].push_back(vec[i][j]);
    }
  }
  int ans = -1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) visit[j] = -1;
    queue<pair<int, int> > q;
    q.push(make_pair(i, -1));
    visit[i] = 0;
    int g = INT_MAX;
    while (!q.empty()) {
      int f = q.front().first;
      int h = q.front().second;
      q.pop();
      for (int j = 0; j < vec1[f].size(); j++) {
        if (vec1[f][j] == h) continue;
        if (visit[vec1[f][j]] > -1) {
          g = min(g, visit[vec1[f][j]] + visit[f] + 1);
          continue;
        }
        visit[vec1[f][j]] = visit[f] + 1;
        q.push(make_pair(vec1[f][j], f));
      }
    }
    if (ans == -1 && g > 2 && g != INT_MAX)
      ans = g;
    else if (g > 2)
      ans = min(ans, g);
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      n--;
      i--;
    }
  }
  if (n <= 2) {
    cout << "-1\n";
    return 0;
  }
  if (n <= 3600) {
    solve(n);
    return 0;
  }
  cout << "3\n";
  return 0;
}
