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 inf = 0x3f3f3f3f;
int now, u, t, ans, ff[1005], len, p[200], f[1000005], dist[1000005],
    fa[1000005], n;
vector<int> edge[1000005];
inline int read() {
  int x = 0, y = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') y = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return x * y;
}
inline void bfs(int x) {
  queue<int> q;
  memset(dist, inf, sizeof dist);
  q.push(x);
  dist[x] = 0;
  fa[x] = x;
  while (!q.empty()) {
    now = q.front();
    q.pop();
    for (int i = 0; i < edge[now].size(); i++)
      if (edge[now][i] != fa[now]) {
        u = edge[now][i];
        if (dist[u] != inf)
          ans = min(ans, dist[u] + dist[now] + 1);
        else
          dist[u] = dist[now] + 1, q.push(u), fa[u] = now;
      }
  }
  return;
}
int main() {
  for (int i = 2; i <= 1000; i++)
    if (ff[i] == 0) {
      p[++len] = i;
      ff[i] = len;
      t = 2;
      while (t * i <= 1000) ff[t * i] = -1, t++;
    }
  p[0] = 1;
  n = read();
  ans = inf;
  while (n--) {
    t = read();
    for (int i = 1; i <= len; i++) {
      while (t % (p[i] * p[i]) == 0) t /= p[i] * p[i];
      if (t < p[i] * p[i]) break;
    }
    if (t == 1) {
      printf("1\n");
      return 0;
    }
    if (f[t]) ans = 2;
    f[t] = 1;
    if (t < 1000 && ff[t] != -1) {
      edge[0].push_back(ff[t]);
      continue;
    }
    u = 0;
    for (int i = 1; i <= len; i++)
      if (t % p[i] == 0) {
        t /= p[i];
        u = i;
        break;
      }
    if (t > 1000)
      edge[u].push_back(t), edge[t].push_back(u);
    else
      edge[ff[t]].push_back(u), edge[u].push_back(ff[t]);
  }
  if (ans == 2) {
    printf("2\n");
    return 0;
  }
  for (int i = 0; i <= len; i++)
    if (edge[i].size()) bfs(i);
  if (ans == inf)
    printf("-1\n");
  else
    printf("%d\n", ans);
}