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 = 1010101;
const int qwq = 1010;
const int inf = 0x3f3f3f3f;
int n, m;
int dep[N], vis[N];
vector<int> e[N];
int ans = inf;
int st[N], cnt;
inline int read() {
  int sum = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  return sum * f;
}
void BFS(int u) {
  dep[u] = 0;
  queue<int> q;
  q.push(u);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    if (vis[u]) continue;
    vis[u] = 1;
    st[++cnt] = u;
    for (int i = 0; i < e[u].size(); i++) {
      int v = e[u][i];
      if (dep[v] >= dep[u]) ans = min(ans, dep[v] + dep[u] + 1);
      dep[v] = min(dep[v], dep[u] + 1);
      if (!vis[v]) q.push(v);
    }
  }
  while (cnt) dep[st[cnt]] = inf, vis[st[cnt]] = 0, cnt--;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    int a = read(), sq = sqrt(a), x1 = 0, x2 = 1;
    for (int j = 2; j <= sq; j++) {
      if (a % j) continue;
      int res = 0;
      while (a % j == 0) a /= j, res++;
      if (!(res & 1)) continue;
      if (x1)
        x2 = j;
      else
        x1 = j;
    }
    if (a != 1) {
      if (!x1)
        x1 = a;
      else
        x2 = a;
    }
    if (!x1) {
      cout << 1;
      return 0;
    }
    e[x1].push_back(x2);
    e[x2].push_back(x1);
  }
  memset(dep, 0x3f, sizeof(dep));
  for (int i = 1; i <= 1000; i++) {
    if (e[i].size() == 0) continue;
    BFS(i);
  }
  cout << ((ans == inf) ? -1 : ans);
  return 0;
}