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;
vector<int> v[N];
vector<int> dist(N, 0);
vector<int> primes;
const int inf = (1 << 30);
void out(int a) {
  printf("%d\n", a);
  exit(0);
}
int solve(int src) {
  int res = inf;
  queue<pair<int, int>> q;
  q.push({src, src});
  dist[1] = -1;
  for (int p : primes) dist[p] = -1;
  dist[src] = 0;
  while (!q.empty()) {
    auto [from, a] = q.front();
    q.pop();
    for (int to : v[a]) {
      if (to == from) continue;
      if (dist[to] != -1) {
        res = min(res, dist[a] + dist[to] + 1);
        continue;
      }
      dist[to] = dist[a] + 1;
      q.push({a, to});
    }
  }
  return res;
}
int main() {
  vector<int> p(N);
  for (int i = 0; i < N; i++) p[i] = i;
  for (long long o = 2; o < N; o++) {
    if (p[o] != o) continue;
    primes.push_back(o);
    for (long long i = o * o; i < N; i += o)
      if (o < p[i]) p[i] = o;
  }
  int n;
  scanf("%d", &n);
  map<array<int, 2>, int> m;
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    vector<array<int, 2>> t;
    while (a > 1) {
      if (!t.empty() && p[a] == t.back()[0])
        t.back()[1]++;
      else
        t.push_back({p[a], 1});
      a /= p[a];
    }
    vector<int> x;
    for (auto b : t)
      if (b[1] & 1) x.push_back(b[0]);
    if (x.size() == 0)
      out(1);
    else if (x.size() == 1)
      m[{1, x[0]}]++;
    else if (x.size() == 2)
      m[{x[0], x[1]}]++;
  }
  for (auto x : m)
    if (x.second > 1) out(2);
  for (auto [x, t] : m) {
    v[x[0]].push_back(x[1]);
    v[x[1]].push_back(x[0]);
  }
  int res = inf;
  for (int i = 1; i <= 1000; i++)
    if (p[i] == i) res = min(res, solve(i));
  if (res == inf) res = -1;
  out(res);
  return 0;
}