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;
int a[N], dis[N], ans, num;
bool vis[N];
vector<int> pic[N], prime;
queue<int> que;
void read(int &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + ch - '0';
    ch = getchar();
  }
  x *= f;
}
int init(int x) {
  for (int i = 2; i * i <= x; i++) {
    if (x % i) continue;
    int cnt = 0;
    while (x % i == 0) {
      x /= i;
      cnt++;
    }
    if (cnt & 1) x *= i;
  }
  return x;
}
void bfs(int s) {
  while (!que.empty()) que.pop();
  for (int i = 0; i < num; i++) {
    dis[prime[i]] = N;
    vis[prime[i]] = 0;
  }
  vis[s] = 1;
  que.push(s);
  dis[s] = 0;
  while (!que.empty()) {
    int now = que.front();
    que.pop();
    vis[now] = 0;
    for (int i = 0; i < pic[now].size(); i++) {
      int t = pic[now][i];
      if (dis[t] > dis[now] + 1) {
        dis[t] = dis[now] + 1;
        que.push(t);
        vis[t] = 1;
      } else if (vis[t])
        ans = min(ans, dis[t] + dis[now] + 1);
    }
  }
}
int main() {
  int n, maxn = -1;
  read(n);
  for (int i = 1; i <= n; i++) {
    read(a[i]);
    maxn = max(a[i], maxn);
    a[i] = init(a[i]);
  }
  sort(a + 1, a + 1 + n);
  if (a[1] == 1) {
    printf("1\n");
    return 0;
  }
  int len = unique(a + 1, a + 1 + n) - a - 1;
  if (len < n) {
    printf("2\n");
    return 0;
  }
  for (int i = 1; i <= len; i++) {
    vector<int> tmp(2, -1);
    tmp[0] = a[i];
    for (int j = 2; j * j <= a[i]; j++) {
      if (a[i] % j == 0) {
        a[i] /= j;
        tmp[0] = j;
        if (a[i] > 1) tmp[1] = a[i];
        break;
      }
    }
    if (tmp[1] == -1) tmp[1] = 1;
    for (int j = 0; j < tmp.size(); j++) prime.push_back(tmp[j]);
    pic[tmp[0]].push_back(tmp[1]);
    pic[tmp[1]].push_back(tmp[0]);
  }
  sort(prime.begin(), prime.end());
  num = unique(prime.begin(), prime.end()) - prime.begin();
  ans = N;
  for (int i = 0; i < num; i++) {
    if (1LL * prime[i] * prime[i] >= maxn) break;
    bfs(prime[i]);
  }
  printf("%d\n", ans == N ? -1 : ans);
  return 0;
}