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, vis[1000009], p[1000009], dis[1000009], inf = 1e9, ans = 1e9,
                                               src[1000009];
vector<int> v[1000009], nodes;
vector<pair<int, int> > edges;
void seive() {
  for (int i = 2; i <= 1e6; i++)
    if (!p[i])
      for (int j = i; j <= 1e6; j += i)
        if (!p[j]) p[j] = i;
}
bool take_input() {
  seive();
  p[1] = 1;
  int good = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    vector<int> vv;
    while (x > 1) {
      int r = p[x], cnt = 0;
      while (x % r == 0) x /= r, cnt++;
      if (cnt % 2) vv.push_back(r);
    }
    if (vv.empty()) good = 1;
    if (vv.size() == 1) vv.push_back(1);
    for (auto j : vv) x *= j, nodes.push_back(j);
    if (vv.size() == 2)
      v[vv[0]].push_back(vv.back()), v[vv.back()].push_back(vv[0]),
          edges.push_back({vv.back(), vv[0]});
    vis[x]++;
  }
  return good;
}
void solve(int node) { int ans = inf; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  if (take_input()) return cout << 1, 0;
  for (int i = 1; i <= 1e6; i++)
    if (vis[i] > 1) return cout << 2, 0;
  for (int i = 1; i <= 1e3; i++) {
    if (p[i] != i) continue;
    for (auto j : nodes) dis[j] = inf;
    dis[i] = 0;
    queue<pair<int, int> > q;
    for (auto j : v[i]) q.push({j, j}), src[j] = j, dis[j] = 1;
    while (!q.empty()) {
      int node = q.front().first, s = q.front().second;
      q.pop();
      for (auto j : v[node])
        if (dis[j] > dis[node] + 1)
          dis[j] = dis[node] + 1, q.push({j, s}), src[j] = s;
    }
    for (auto j : edges)
      if (j.first != i && j.second != i && src[j.first] != src[j.second]) {
        ans = min(ans, dis[j.first] + dis[j.second] + 1);
      }
  }
  if (ans == inf) ans = -1;
  cout << ans;
}