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;
const long long N = 1e6 + 10;
const long long K = 2e6;
const long long inf = 1e18;
const long long mod = 998244353;
long long n;
long long a[N];
vector<pair<long long, long long> > g[N];
bool used[N];
long long d[N];
long long glid;
long long q[N];
long long shortest_cyc(long long src) {
  long long res = inf;
  fill(used, used + (long long)1e5 + 10, false);
  fill(d, d + N, inf);
  long long qt = 0;
  long long qh = 0;
  q[qt++] = src;
  d[src] = 0;
  while (qh < qt) {
    long long v = q[qh++];
    for (auto p : g[v])
      if (!used[p.second]) {
        long long u = p.first;
        used[p.second] = true;
        if (d[u] == inf) {
          d[u] = d[v] + 1;
          q[qt++] = u;
        } else
          res = min(res, d[v] + d[u] + 1);
      }
  }
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 0; i < n; ++i) cin >> a[i];
  for (long long i = 0; i < n; ++i) {
    for (long long j = 2; j * j <= a[i]; ++j)
      if (a[i] % (j * j) == 0) {
        a[i] /= (j * j);
        j = 1;
      }
  }
  for (long long i = 0; i < n; ++i) {
    vector<long long> v;
    if (a[i] == 1) {
      cout << 1 << endl;
      return 0;
    }
    for (long long j = 2; j * j <= a[i]; ++j)
      if (a[i] % j == 0) {
        v.push_back(j);
        a[i] /= j;
        j = 1;
      }
    v.push_back(a[i]);
    if (v.size() == 1) v.push_back(1);
    g[v[0]].emplace_back(v[1], glid);
    g[v[1]].emplace_back(v[0], glid);
    ++glid;
  }
  long long ans = inf;
  for (long long i = 1; i <= 1e3; ++i) ans = min(ans, shortest_cyc(i));
  if (ans == inf)
    cout << -1 << endl;
  else
    cout << ans << endl;
}