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 = 1e6 + 5, M = 2e6 + 5, INF = 0x3f3f3f3f;
int n, res, dis[N];
unordered_set<int> nums;
int h[N], e[M], ne[M], idx;
bool vis[M];
void add(int u, int v) { e[idx] = v, ne[idx] = h[u], h[u] = idx++; }
void init() {
  for (int i = 1; i < N; i++) dis[i] = -1;
  for (int i = 0; i < idx; i++) vis[i] = false;
  return;
}
void bfs(int st) {
  init();
  queue<int> q;
  q.push(st);
  dis[st] = 0;
  while (!q.empty()) {
    int t = q.front();
    q.pop();
    if (2 * dis[t] + 1 >= res) break;
    for (int i = h[t]; ~i; i = ne[i]) {
      int j = e[i];
      if (vis[i]) continue;
      vis[i] = vis[i ^ 1] = true;
      if (dis[j] != -1)
        res = min(res, dis[t] + dis[j] + 1);
      else {
        dis[j] = dis[t] + 1;
        q.push(j);
      }
    }
  }
  return;
}
int main() {
  scanf("%d", &n);
  memset(h, -1, sizeof h);
  nums.insert(1);
  while (n--) {
    int x;
    scanf("%d", &x);
    int p, q;
    p = q = 0;
    for (int i = 2; i <= x / i; i++)
      if (x % i == 0) {
        int s = 0;
        while (x % i == 0) {
          s++;
          x /= i;
        }
        if (s & 1)
          if (!p)
            p = i;
          else
            q = i;
      }
    if (x > 1)
      if (!p)
        p = x;
      else
        q = x;
    if (p && p <= 1000) nums.insert(p);
    if (q && q <= 1000) nums.insert(q);
    if (p && q)
      add(q, p), add(p, q);
    else if (q)
      add(1, q), add(q, 1);
    else if (p)
      add(1, p), add(p, 1);
    else {
      cout << 1 << endl;
      return 0;
    }
  }
  res = INF;
  for (auto t : nums) bfs(t);
  if (res == INF) res = -1;
  printf("%d\n", res);
  return 0;
}