Problem: You are given an array a of length n that has a special condition: every element in this array has at most 7 divisors. Find the length of the shortest non-empty subsequence of this array product of whose elements is a perfect square.

A sequence a is a subsequence of an array b if a can be obtained from b by deletion of several (possibly, zero or all) elements.

Input

The first line contains an integer n (1 ≤ n ≤ 10^5) — the length of a.

The second line contains n integers a_1, a_2, …, a_{n} (1 ≤ a_i ≤ 10^6) — the elements of the array a.

Output

Output the length of the shortest non-empty subsequence of a product of whose elements is a perfect square. If there are several shortest subsequences, you can find any of them. If there's no such subsequence, print "-1".

Examples

Input


3
1 4 6


Output


1

Input


4
2 3 6 6


Output


2

Input


3
6 15 10


Output


3

Input


4
2 3 5 7


Output


-1

Note

In the first sample, you can choose a subsequence [1].

In the second sample, you can choose a subsequence [6, 6].

In the third sample, you can choose a subsequence [6, 15, 10].

In the fourth sample, there is no such subsequence.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
using namespace std;
bool IsPrime[MAX];
long long MinFactor[MAX];
vector<long long> preprocess(long long n = MAX) {
  vector<long long> res;
  for (long long i = 0; i < n; ++i) IsPrime[i] = true, MinFactor[i] = -1;
  IsPrime[0] = false;
  IsPrime[1] = false;
  MinFactor[0] = 0;
  MinFactor[1] = 1;
  for (long long i = 2; i < n; ++i) {
    if (IsPrime[i]) {
      MinFactor[i] = i;
      res.push_back(i);
      for (long long j = i * 2; j < n; j += i) {
        IsPrime[j] = false;
        if (MinFactor[j] == -1) MinFactor[j] = i;
      }
    }
  }
  return res;
}
vector<pair<long long, long long>> fast_prime_factor_E(long long n) {
  vector<pair<long long, long long>> res;
  while (n != 1) {
    long long prime = MinFactor[n];
    long long exp = 0;
    while (MinFactor[n] == prime) {
      ++exp;
      n /= prime;
    }
    if (exp & 1) res.push_back(make_pair(prime, 1));
  }
  return res;
}
vector<int> comp;
int get_idx(int x) {
  return lower_bound(comp.begin(), comp.end(), x) - comp.begin();
}
int main() {
  preprocess();
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n; i++) {
    auto vp = fast_prime_factor_E(a[i]);
    if (vp.size() == 0) {
      cout << 1 << endl;
      return 0;
    }
    for (auto p : vp) comp.push_back(p.first);
  }
  comp.push_back(1);
  sort(comp.begin(), comp.end());
  comp.erase(unique(comp.begin(), comp.end()), comp.end());
  vector<vector<int>> g(comp.size());
  for (int i = 0; i < n; i++) {
    auto vp = fast_prime_factor_E(a[i]);
    if (vp.size() == 1) {
      int idx = get_idx(vp[0].first);
      g[0].push_back(idx);
      g[idx].push_back(0);
    } else {
      int idx1 = get_idx(vp[0].first);
      int idx2 = get_idx(vp[1].first);
      g[idx1].push_back(idx2);
      g[idx2].push_back(idx1);
    }
  }
  int res = inf;
  for (int i = 0; i < comp.size(); i++) {
    if (comp[i] >= 1000) break;
    vector<int> d(comp.size(), -1);
    d[i] = 0;
    queue<pair<int, int>> q;
    q.emplace(i, -1);
    int tmp = inf;
    while (!q.empty()) {
      int cur, pre;
      tie(cur, pre) = q.front();
      q.pop();
      for (int next : g[cur]) {
        if (next == pre) continue;
        if (d[next] == -1) {
          d[next] = d[cur] + 1;
          q.emplace(next, cur);
        } else {
          chmin(tmp, d[next] + d[cur] + 1);
        }
      }
    }
    chmin(res, tmp);
  }
  if (res == inf) res = -1;
  cout << res << endl;
  return 0;
}