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 ans = 1e9;
const long long MAXA = 1000100;
vector<long long> g[MAXA];
long long p[MAXA];
long long c[MAXA];
void bfs(long long v) {
  vector<long long> q = {v};
  p[v] = -1;
  c[v] = 0;
  for (long long i = 0; i < q.size(); i++) {
    long long x = q[i];
    for (auto u : g[x]) {
      if (c[u] == -1) {
        c[u] = c[x] + 1;
        p[u] = x;
        q.push_back(u);
      } else {
        if (u != p[x]) {
          ans = min(ans, c[u] + c[x] + 1);
        }
      }
    }
  }
}
signed main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  vector<pair<long long, long long> > primes(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long i = 0; i < n; i++) {
    vector<long long> divisiors;
    for (long long T = 2; T * T <= a[i]; T++) {
      while (a[i] % (T * T) == 0) {
        a[i] /= T * T;
      }
    }
    for (long long T = 1; T * T <= a[i]; T++) {
      if (a[i] % T == 0) {
        divisiors.push_back(T);
        if (T * T != a[i]) divisiors.push_back(a[i] / T);
      }
    }
    if (divisiors.size() % 2) {
      cout << 1;
      return 0;
    }
    sort(divisiors.begin(), divisiors.end());
    if (divisiors.size() == 4) {
      long long p1 = divisiors[1];
      long long p2 = divisiors[2];
      primes[i] = {p1, p2};
    }
    if (divisiors.size() == 2) {
      long long p = divisiors[1];
      primes[i] = {p, 1};
    }
  }
  for (long long i = 0; i < n; i++) {
    g[primes[i].first].push_back(primes[i].second);
    g[primes[i].second].push_back(primes[i].first);
  }
  for (long long i = 1; i <= 1000; i++) {
    long long t = 1;
    for (long long j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        t = 0;
      }
    }
    if (t) {
      fill(c, c + MAXA, -1);
      bfs(i);
    }
  }
  if (ans == 1e9) {
    cout << -1;
    return 0;
  }
  cout << ans;
}