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;
int n, tot, cnt;
int w[100005], head[1000005], d[1000005], p[200005];
bool vis[200005], vit[1000005];
map<pair<int, int>, bool> mp;
struct node {
  int v, id, next;
} a[100005 << 1];
int bfs(int x) {
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i < cnt; i++) d[p[i]] = 0;
  queue<int> q;
  q.push(x);
  d[x] = 1;
  while (q.size()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; i != -1; i = a[i].next) {
      int v = a[i].v;
      if (vis[a[i].id]) continue;
      vis[a[i].id] = true;
      if (d[v]) return d[u] + d[v] - 1;
      d[v] = d[u] + 1;
      q.push(v);
    }
  }
  return 0x3f3f3f3f;
}
int main() {
  memset(head, -1, sizeof(head));
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &w[i]);
  int ans = 0x3f3f3f3f;
  for (int i = 1; i <= n; i++) {
    int x = w[i];
    int p1 = 1, p2 = 1;
    for (int j = 2; j * j <= x; j++) {
      if (x % j == 0) {
        int num = 0;
        while (x % j == 0) x /= j, num++;
        if (num & 1) {
          if (p1 == 1)
            p1 = j;
          else
            p2 = j;
        }
      }
    }
    if (x > 1) {
      if (p1 == 1)
        p1 = x;
      else
        p2 = x;
    }
    if (p1 == 1 && p2 == 1) ans = 1;
    if (!vit[p1]) p[cnt++] = p1, vit[p1] = true;
    if (!vit[p2]) p[cnt++] = p2, vit[p2] = true;
    if (p1 > p2) swap(p1, p2);
    if (mp.count(make_pair(p1, p2)))
      ans = min(ans, 2);
    else {
      a[tot] = node{p1, i, head[p2]}, head[p2] = tot++;
      a[tot] = node{p2, i, head[p1]}, head[p1] = tot++;
      mp[make_pair(p1, p2)] = true;
    }
  }
  for (int i = 1; i <= 1000; i++) ans = min(ans, bfs(i));
  if (ans == 0x3f3f3f3f)
    printf("-1\n");
  else
    printf("%d\n", ans);
  return 0;
}