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 = 1e5 + 2;
int n, d[maxn * 10], ans = 1e6;
vector<int> g[maxn * 10], pr;
bool kt[maxn * 10], ch = false;
map<vector<int>, int> m;
struct T {
  int u, v;
};
void Enter() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    vector<int> divi;
    for (int j = 2; j * j <= a; j++) {
      int dem = 0;
      while (a % j == 0) {
        dem++;
        a /= j;
      }
      if (dem % 2) divi.push_back(j);
    }
    if (a != 1) divi.push_back(a);
    if (divi.size() == 0) {
      cout << 1;
      exit(0);
    }
    if (divi.size() == 1) {
      divi.push_back(1);
      swap(divi[0], divi[1]);
    }
    g[divi[0]].push_back(divi[1]);
    g[divi[1]].push_back(divi[0]);
    if (m[divi] == 1) ch = true;
    m[divi] = 1;
  }
  if (ch) {
    cout << 2;
    exit(0);
  }
}
void Solve() {
  for (int i = 2; i * i <= 1e6; i++)
    if (!kt[i])
      for (int j = i * i; j <= 1e6; j += i) kt[j] = true;
  for (int i = 1; i <= 1e6; i++)
    if (!kt[i]) pr.push_back(i);
  for (int i : pr) {
    if (i * i > maxn) break;
    for (int j : pr) d[j] = 0;
    queue<T> p;
    d[i] = 1;
    p.push({i, 0});
    while (!p.empty()) {
      T a = p.front();
      p.pop();
      for (int v : g[a.u])
        if (v != a.u && v != a.v) {
          if (d[v] == 0) {
            d[v] = d[a.u] + 1;
            p.push({v, a.u});
          } else
            ans = min(ans, d[a.u] + d[v] - 1);
        }
    }
  }
  if (ans != 1e6)
    cout << ans;
  else
    cout << -1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  Enter();
  Solve();
}