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 = 1000005;
int a, n, m, k, s, t, c, ans;
int fz[N], dp[N], kk[5];
int ft[N], nt[N], to[N];
queue<int> qq;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a);
    c = 0;
    kk[2] = 1;
    for (int j = 2; j * j <= a; j++) {
      if (a % j == 0) {
        k = 0;
        while (a % j == 0) {
          k++;
          a /= j;
        }
        if (k % 2 == 1) {
          c++;
          kk[c] = j;
        }
      }
    }
    c++;
    kk[c] = a;
    if (c == 0) {
      printf("1\n");
      return 0;
    }
    m++;
    to[m] = kk[1];
    nt[m] = ft[kk[2]];
    ft[kk[2]] = m;
    m++;
    to[m] = kk[2];
    nt[m] = ft[kk[1]];
    ft[kk[1]] = m;
  }
  ans = N;
  for (int i = 1; i <= 1000; i++) {
    memset(dp, -1, sizeof(dp));
    dp[i] = 0;
    qq.push(i);
    while (!qq.empty()) {
      s = qq.front();
      qq.pop();
      for (int j = ft[s]; j != 0; j = nt[j]) {
        t = to[j];
        if (t == fz[s]) {
          continue;
        }
        if (dp[t] == -1) {
          dp[t] = dp[s] + 1;
          fz[t] = s;
          qq.push(t);
        } else {
          ans = min(ans, dp[s] + dp[t] + 1);
        }
      }
    }
  }
  if (ans == N) {
    ans = -1;
  }
  printf("%d\n", ans);
  return 0;
}