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 = 1e5 + 3;
const int A = 1e6 + 3;
const int inf = 1e9;
int n, qf, qb, ans, par[A], d[A], minPrime[A], qu[N];
vector<int> a[A];
int main() {
  for (int i = 2; i * i < A; i++)
    if (minPrime[i] == 0) {
      for (int j = i * i; j < A; j += i)
        if (minPrime[j] == 0) {
          minPrime[j] = i;
        }
    }
  for (int i = 2; i < A; i++)
    if (minPrime[i] == 0) minPrime[i] = i;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x, u = 0, v = 0;
    cin >> x;
    while (x != 1) {
      int tmp = minPrime[x], cnt = 0;
      while (x != 1 && x % tmp == 0) {
        x /= tmp;
        cnt++;
      }
      if (cnt % 2 == 0) continue;
      if (u == 0)
        u = tmp;
      else
        v = tmp;
    }
    if (u == 0 && v == 0) {
      u = 1;
      v = 1;
    } else if (v == 0)
      v = 1;
    a[u].push_back(v);
    a[v].push_back(u);
  }
  ans = inf;
  minPrime[1] = 1;
  for (int i = 1; i <= 1000; i++)
    if (minPrime[i] == i) {
      qf = qb = 0;
      qu[0] = i;
      par[i] = -1;
      for (int j = 1; j < A; j++) d[j] = inf;
      d[i] = 0;
      while (qf <= qb) {
        bool skp = true;
        int u = qu[qf++];
        for (int j = 0; j < a[u].size(); j++) {
          int v = a[u][j];
          if (d[v] == inf) {
            d[v] = d[u] + 1;
            par[v] = u;
            qu[++qb] = v;
          } else {
            if (par[u] == v && skp) {
              skp = false;
              continue;
            }
            ans = min(ans, d[u] + d[v] + 1);
          }
        }
      }
    }
  cout << (ans == inf ? -1 : ans);
  return 0;
}