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, ans = 0x3f3f3f3f, dis[1000015];
bool gkp[1000015];
vector<int> a, p, e[1000015];
queue<int> q;
int check(int x) {
  for (int i = 2; i * i <= x; ++i) {
    if (x % i) continue;
    int cnt = 0;
    while (x % i == 0) {
      cnt++;
      x /= i;
    }
    if (cnt % 2 == 1) x *= i;
  }
  return x;
}
void bfs(int x) {
  for (int i = 0; i < p.size(); ++i) dis[p[i]] = 0x3f3f3f3f, gkp[p[i]] = 0;
  while (!q.empty()) q.pop();
  q.push(x);
  gkp[x] = 1;
  dis[x] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    gkp[u] = 0;
    for (int i = 0; i < e[u].size(); ++i) {
      int v = e[u][i];
      if (dis[v] > dis[u] + 1) {
        dis[v] = dis[u] + 1;
        q.push(v);
        gkp[v] = 1;
      } else if (gkp[v])
        ans = min(ans, dis[u] + dis[v] + 1);
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int temp;
    scanf("%d", &temp);
    a.push_back(check(temp));
  }
  sort(a.begin(), a.end());
  if (a[0] == 1) {
    puts("1");
    return 0;
  }
  a.erase(unique(a.begin(), a.end()), a.end());
  if (a.size() < n) {
    puts("2");
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    int cur[2];
    cur[0] = a[i];
    cur[1] = -1;
    for (int j = 2; j * j <= a[i]; ++j) {
      if (a[i] % j) continue;
      cur[0] = j;
      if ((a[i] / j) != 1) cur[1] = a[i] / j;
      break;
    }
    if (cur[1] == -1) cur[1] = 1;
    p.push_back(cur[0]);
    p.push_back(cur[1]);
    e[cur[0]].push_back(cur[1]);
    e[cur[1]].push_back(cur[0]);
  }
  sort(p.begin(), p.end());
  p.erase(unique(p.begin(), p.end()), p.end());
  for (int i = 1; i <= 1000; ++i) {
    if (e[i].empty()) continue;
    bfs(i);
  }
  if (ans == 0x3f3f3f3f)
    printf("-1");
  else
    printf("%d", ans);
  return 0;
}