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 main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &e : a) cin >> e;
  const int MAXN = 1e6 + 5;
  vector<vector<int>> adj(MAXN);
  for (auto e : a) {
    for (int i = 2; 1LL * i * i <= e; ++i)
      if (e % i == 0) {
        while (e % (i * i) == 0) e /= i * i;
      }
    if (e == 1) {
      cout << 1 << '\n';
      exit(0);
    }
    int fac1 = 1, fac2 = e;
    for (int i = 2; 1LL * i * i <= e; ++i)
      if (e % i == 0) fac1 = e / i, fac2 = i;
    adj[fac1].push_back(fac2);
    adj[fac2].push_back(fac1);
  }
  int ans = INT_MAX;
  for (int i = 1; i * i < MAXN; ++i) {
    auto bfs = [&](int x) {
      vector<int> dis(MAXN, INT_MAX);
      dis[x] = 0;
      queue<pair<int, int>> q;
      q.push({x, -1});
      while (!q.empty()) {
        int u, fa;
        tie(u, fa) = q.front();
        q.pop();
        for (auto e : adj[u]) {
          if (e == fa) continue;
          if (dis[e] == INT_MAX) {
            q.push({e, u});
            dis[e] = dis[u] + 1;
          } else
            return dis[e] + dis[u] + 1;
        }
      }
      return INT_MAX;
    };
    ans = min(ans, bfs(i));
  }
  cout << (ans == INT_MAX ? -1 : ans) << '\n';
  return 0;
}