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 + 7;
int n, pa[MAXN], min_div[MAXN], pos[MAXN] = {}, d[MAXN];
vector<int> adj[MAXN];
void sieve() {
  for (int i = 2; i < MAXN; ++i)
    if (!min_div[i])
      for (int j = i; j < MAXN; j += i)
        if (min_div[j] == 0) min_div[j] = i;
}
int get_pr_div(int &n) {
  if (n == 1) return 1;
  int ret = min_div[n], ok = 0;
  while (n % ret == 0) ok ^= 1, n /= ret;
  return (ok ? ret : 1);
}
void solve() {
  sieve();
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    int u = get_pr_div(x);
    int v = get_pr_div(x);
    if (u == 1 && v == 1) return cout << 1, void();
    adj[u].push_back(v), adj[v].push_back(u);
  }
  int res = n + 1;
  for (int i = 1; i <= 1000; ++i)
    if (min_div[i] == i || i == 1) {
      queue<int> q;
      d[i] = 0, pos[i] = i;
      q.push(i);
      while (q.size()) {
        int u = q.front();
        q.pop();
        for (auto v : adj[u])
          if (v != pa[u]) {
            if (pos[v] != i) {
              pos[v] = i, pa[v] = u;
              d[v] = d[u] + 1;
              q.push(v);
            } else
              res = min(res, d[u] + d[v] + 1);
          }
      }
    }
  cout << (res == n + 1 ? -1 : res);
}
void input() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
}
int main() {
  input();
  solve();
  return 0;
}