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;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ld = long double;
const int MN = 2e5 + 3, MOD = 1e9 + 7;
vector<int> adj[1000005];
int dist[1000005], par[1000005];
int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  set<int> seen;
  int ans = INT_MAX;
  vector<int> att, nodes;
  for (auto &au : a) {
    scanf("%d", &au);
    if (seen.count(au)) ans = 2;
    seen.insert(au);
    int cur = au, fac1 = -1, fac2 = -1;
    for (int i = 2; i * i <= cur; i++)
      if (cur % i == 0) {
        int cnt = 0;
        while (cur % i == 0) cur /= i, cnt++;
        if (cnt & 1) (~fac1 ? fac2 : fac1) = i;
      }
    if (cur > 1) (~fac1 ? fac2 : fac1) = cur;
    if (!(~fac1)) return !printf("1\n");
    if (!(~fac2)) fac2 = 1;
    adj[fac1].push_back(fac2);
    adj[fac2].push_back(fac1);
    if (fac1 <= 1000) att.push_back(fac1);
    if (fac2 <= 1000) att.push_back(fac2);
    nodes.push_back(fac1);
    nodes.push_back(fac2);
  }
  if (ans == 2) return !printf("2\n");
  sort((att).begin(), (att).end());
  att.erase(unique((att).begin(), (att).end()), att.end());
  sort((nodes).begin(), (nodes).end());
  nodes.erase(unique((nodes).begin(), (nodes).end()), nodes.end());
  for (int st : att) {
    for (int i : nodes) dist[i] = n + 3, par[i] = 0;
    dist[st] = 0;
    queue<int> q;
    q.push(st);
    while (!q.empty()) {
      int cur = q.front();
      q.pop();
      for (int i : adj[cur]) {
        if (dist[cur] + 1 < dist[i]) {
          dist[i] = dist[cur] + 1;
          par[i] = cur;
          q.push(i);
        } else if (i != par[cur]) {
          ans = min(ans, dist[cur] + dist[i] + 1);
        }
      }
    }
  }
  printf("%d\n", ans > n ? -1 : ans);
  return 0;
}