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 maxn = 1e6 + 5;
vector<int> G[maxn];
int n, d[maxn], fa[maxn];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    vector<pair<int, int>> factor;
    for (int j = 2; j * j <= x; j++) {
      if (x % j) continue;
      factor.push_back({j, 0});
      while (x % j == 0) factor.back().second++, x /= j;
    }
    if (x != 1) {
      factor.push_back({x, 1});
    }
    for (int i = factor.size() - 1; i >= 0; i--) {
      if (factor[i].second % 2 == 0) factor.erase(factor.begin() + i);
    }
    while (factor.size() < 2) factor.push_back({1, 1});
    G[factor[0].first].push_back(factor[1].first);
    G[factor[1].first].push_back(factor[0].first);
  }
  int ans = 1e9;
  memset(d, 0x3f, sizeof(d));
  for (int i = 1; i <= 1000; i++) {
    d[i] = 0;
    queue<int> q, rq;
    fa[i] = -1;
    q.push(i);
    while (q.size()) {
      int x = q.front();
      q.pop();
      rq.push(x);
      bool skp = 1;
      for (int y : G[x]) {
        if (d[y] > 1e9) {
          d[y] = d[x] + 1;
          fa[y] = x;
          q.push(y);
        } else {
          if (y == fa[x] && skp)
            skp = 0;
          else
            ans = min(ans, d[x] + d[y] + 1);
        }
      }
    }
    while (rq.size()) {
      d[rq.front()] = d[0];
      rq.pop();
    }
  }
  printf("%d\n", ans == 1e9 ? -1 : ans);
}