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 maxn = 1e6 + 10;
int n, ans = 2e9;
vector<int> a, fac;
vector<int> vec[maxn];
int dis[maxn];
bool vis[maxn];
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 x) {
  for (auto i : fac) dis[i] = 2e9, vis[i] = 0;
  dis[x] = 0;
  queue<int> q;
  q.push(x);
  vis[x] = true;
  while (!q.empty()) {
    int top = q.front();
    q.pop();
    vis[top] = false;
    for (auto i : vec[top]) {
      if (dis[i] > dis[top] + 1) {
        dis[i] = dis[top] + 1;
        q.push(i);
        vis[i] = true;
      } else if (vis[i])
        ans = min(ans, dis[top] + dis[i] + 1);
    }
  }
}
int main() {
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i] = init(a[i]);
  }
  sort(a.begin(), a.end());
  if (a[0] == 1) {
    cout << "1" << endl;
    return 0;
  }
  a.erase(unique(a.begin(), a.end()), a.end());
  if (a.size() < n) {
    cout << "2" << endl;
    return 0;
  }
  for (auto i : a) {
    vector<int> tmp(2, -1);
    tmp[0] = i;
    for (int j = 2; j * j <= i; ++j) {
      if (i % j) continue;
      tmp[0] = j;
      i /= j;
      if (i != 1) tmp[1] = i;
      break;
    }
    if (tmp[1] == -1) tmp[1] = 1;
    for (auto j : tmp) fac.emplace_back(j);
    vec[tmp[0]].emplace_back(tmp[1]);
    vec[tmp[1]].emplace_back(tmp[0]);
  }
  sort(fac.begin(), fac.end());
  fac.erase(unique(fac.begin(), fac.end()), fac.end());
  for (int i = 1; i <= 1000; i++) {
    if (vec[i].empty()) continue;
    bfs(i);
  }
  cout << (ans == 2e9 ? -1 : ans);
  return 0;
}