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;
struct edge {
  int to, next, id;
} e[N * 2];
int fl[N], tr[N], id[N], mn[N];
int head[N], tot, n, ans;
int q[N], d[N], fr[N];
void add(int x, int y, int i) {
  x = id[x];
  y = id[y];
  e[++tot] = (edge){y, head[x], i};
  head[x] = tot;
  e[++tot] = (edge){x, head[y], i};
  head[y] = tot;
}
void UPD(int S) {
  S = id[S];
  for (int i = (int)(1); i <= (int)(*id); i++) d[i] = -1, fr[i] = 0;
  int h = 0, t = 1;
  q[1] = S;
  d[S] = 0;
  while (h != t) {
    int x = q[++h];
    for (int i = head[x]; i; i = e[i].next)
      if (e[i].id != fr[x])
        if (d[e[i].to] != -1)
          ans = min(ans, d[e[i].to] + d[x] + 1);
        else {
          d[e[i].to] = d[x] + 1;
          fr[e[i].to] = e[i].id;
          q[++t] = e[i].to;
        }
  }
}
void sieve() {
  for (int i = (int)(2); i <= (int)(N - 1); i++)
    if (!fl[i])
      for (int j = (int)(2); j <= (int)((N - 1) / i); j++) fl[i * j] = 1;
  for (int i = (int)(1); i <= (int)(N - 1); i++) tr[i] = i;
  id[1] = ++*id;
  for (int i = (int)(2); i <= (int)(N - 1); i++)
    if (!fl[i]) {
      id[i] = ++*id;
      for (int j = (int)(1); j <= (int)((N - 1) / i / i); j++)
        for (; tr[i * i * j] % (i * i) == 0; tr[i * i * j] /= i * i)
          ;
      for (int j = (int)(1); j <= (int)((N - 1) / i); j++) mn[i * j] = i;
    }
}
int main() {
  sieve();
  scanf("%d", &n);
  for (int i = (int)(1); i <= (int)(n); i++) {
    int x;
    scanf("%d", &x);
    if (tr[x] == 1) return puts("1"), 0;
    x = tr[x];
    if (mn[x] == x)
      add(x, 1, i);
    else
      add(mn[x], x / mn[x], i);
  }
  ans = 1 << 30;
  for (int i = (int)(1); i <= (int)(1000); i++)
    if (!fl[i]) UPD(i);
  printf("%d\n", ans == 1 << 30 ? -1 : ans);
}