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;
vector<list<int>> adj;
int maxEdge = -1;
int bfs(int u, int par = -1) {
  vector<int> dist(maxEdge + 1, 1e9);
  dist[u] = 0;
  queue<pair<int, int>> q;
  q.push({u, par});
  while (!q.empty()) {
    int v, fa;
    tie(v, fa) = q.front();
    q.pop();
    for (const auto &child : adj[v]) {
      if (child == fa) continue;
      if (dist[child] == 1e9) {
        q.push({child, v});
        dist[child] = dist[v] + 1;
      } else {
        return dist[child] + dist[v] + 1;
      }
    }
  }
  return 1e9;
}
void normalize(int &x) {
  for (int i = 2; i * i <= x; ++i) {
    while (x % (i * i) == 0) {
      x /= (i * i);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> e(n);
  for (int &edge : e) {
    cin >> edge;
    normalize(edge);
    if (edge == 1) return cout << 1, 0;
    if (edge > maxEdge) maxEdge = edge;
  }
  vector<int> lp(maxEdge + 1);
  unordered_set<int> pr;
  pr.insert(1);
  for (int i = 2; i <= maxEdge; ++i) {
    if (!lp[i]) {
      pr.insert(i);
      for (int j = i; j <= maxEdge; j += i) {
        lp[j] = i;
      }
    }
  }
  adj.assign(maxEdge + 1, list<int>());
  for (auto &x : e) {
    int fac1 = 1, fac2 = x;
    bool flag = false;
    for (int i = 2; i * i <= x; ++i) {
      if (x % i == 0) {
        fac1 = i;
        fac2 = x / i;
        adj[fac1].push_back(fac2);
        adj[fac2].push_back(fac1);
        flag = true;
        break;
      }
    }
    if (!flag) {
      adj[fac1].push_back(fac2);
      adj[fac2].push_back(fac1);
    }
  }
  int ans = 1e9;
  for (int i = 1; i * i <= maxEdge; ++i) {
    if (adj[i].size() && pr.count(i)) {
      ans = min(ans, bfs(i));
    }
  }
  return cout << (ans == 1e9 ? -1 : ans), 0;
}