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>
using namespace std;
long long n, mod = 1e9 + 7;
vector<vector<long long>> v(1e6 + 5);
vector<long long> par(1e6 + 5, -1), dis(1e6 + 5, INT_MAX);
long long ans = INT_MAX;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  long long x, mx = 0;
  for (long long j = 1; j <= n; j++) {
    vector<long long> fact;
    cin >> x;
    for (long long i = 2; i * i <= x; i++) {
      if (x % i == 0) {
        long long c = 0;
        while (x % i == 0) {
          x /= i;
          c++;
        }
        c &= 1;
        if (c) fact.push_back(i);
      }
    }
    if (x > 1) {
      fact.push_back(x);
    }
    if (fact.size() == 0) {
      cout << 1;
      return 0;
    }
    if (fact.size() == 1) fact.push_back(1);
    mx = max(mx, fact[1]);
    mx = max(mx, fact[0]);
    v[fact[0]].push_back(fact[1]);
    v[fact[1]].push_back(fact[0]);
  }
  for (long long k = 1; k <= 1000; k++) {
    long long br = 0;
    if (k == 1000) {
      k = mx;
      br = 1;
    }
    queue<long long> q;
    vector<long long> re;
    q.push(k);
    par[k] = -1;
    dis[k] = 0;
    while (!q.empty()) {
      long long skp = 1;
      re.push_back(q.front());
      long long node = q.front();
      q.pop();
      for (auto i : v[node]) {
        if (dis[i] == INT_MAX) {
          dis[i] = dis[node] + 1;
          par[i] = node;
          q.push(i);
        } else {
          if (i == par[node] && skp)
            skp--;
          else
            ans = min(ans, dis[node] + dis[i] + 1);
        }
      }
    }
    for (auto j : re) {
      dis[j] = INT_MAX;
      par[j] = -1;
    }
    if (br) break;
  }
  if (ans == INT_MAX) ans = -1;
  cout << ans;
}