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 int N = 1e6 + 1, I = 1e9;
int n, w[N], t, q[N], c, d[N], p[N], s, x, A = I;
vector<int> a[N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> w[i];
  for (int i = 1; i <= n; i++) {
    t = 0, q[2] = 1;
    for (int j = 2; j * j <= w[i]; j++) {
      c = 0;
      while (w[i] % j == 0) w[i] /= j, c++;
      if (c & 1) q[++t] = j;
    }
    if (w[i] > 1) q[++t] = w[i];
    if (t == 0) A = 1;
    a[q[1]].push_back(q[2]), a[q[2]].push_back(q[1]);
  }
  for (int i = 1; i <= 1000; i++) {
    for (int j = 1; j < N; j++) d[j] = I;
    d[i] = 0, s = t = 0, q[++t] = i;
    while (s < t) {
      x = q[++s];
      for (int j = 0; j < a[x].size(); j++)
        if (a[x][j] != p[x]) {
          if (d[a[x][j]] == I)
            d[a[x][j]] = d[x] + 1, p[a[x][j]] = x, q[++t] = a[x][j];
          else
            A = min(A, d[x] + d[a[x][j]] + 1);
        }
    }
  }
  if (A == I)
    cout << -1;
  else
    cout << A;
  return 0;
}