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 + 5, A = 1e6 + 5, SQRTA = 1000;
const int INF = 0x3f3f3f3f;
int n, ncnt, hd, tl, que[N][2], ans = INF;
int a[N], prm[N], id[A], h[N], dis[N];
bool npr[A];
struct edge {
  int v, nxt;
} e[A << 1];
void EulerSieve() {
  for (int i = 2; i < A; i++) {
    if (!npr[i]) prm[++prm[0]] = i, id[i] = prm[0] + 1;
    for (int j = 1; j <= prm[0] && i * prm[j] < A; j++) {
      npr[i * prm[j]] = true;
      if (i % prm[j] == 0) break;
    }
  }
}
inline void AddEdge(int u, int v) {
  e[++ncnt] = (edge){v, h[u]};
  h[u] = ncnt;
  e[++ncnt] = (edge){u, h[v]};
  h[v] = ncnt;
}
void Divide(int x) {
  int p[4] = {0}, k[4] = {0};
  for (int i = 1; i <= prm[0] && prm[i] * prm[i] <= x; i++) {
    if (x % prm[i] == 0) {
      p[++p[0]] = prm[i];
      while (x % prm[i] == 0) k[p[0]] ^= 1, x /= prm[i];
      if (!k[p[0]]) p[0]--;
    }
  }
  if (x > 1) p[++p[0]] = x, k[p[0]] = 1;
  if (!p[0]) {
    cout << 1 << endl;
    exit(0);
  } else if (p[0] == 1)
    AddEdge(1, id[p[1]]);
  else
    AddEdge(id[p[1]], id[p[2]]);
}
void Bfs(int s) {
  memset(dis, 0x3f, sizeof dis);
  dis[s] = 0;
  que[1][0] = s;
  que[1][1] = 0;
  hd = tl = 1;
  while (hd <= tl) {
    int u = que[hd][0], fa = que[hd][1];
    hd++;
    for (int i = h[u]; i; i = e[i].nxt) {
      int v = e[i].v;
      if (v == fa) continue;
      if (dis[v] == INF) {
        tl++;
        que[tl][0] = v;
        que[tl][1] = u;
        dis[v] = dis[u] + 1;
      } else
        ans = min(ans, dis[u] + dis[v] + 1);
    }
  }
}
int main() {
  cin >> n;
  for (register int i = 1; i <= n; i++) cin >> a[i];
  EulerSieve();
  for (register int i = 1; i <= n; i++) Divide(a[i]);
  for (register int i = 1; i <= SQRTA; i++) Bfs(i);
  if (ans == INF)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}