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 maxa = 1e6 + 5;
int n, d[maxa], par[maxa];
vector<int> adj[maxa];
int bfs(int u) {
  queue<int> Q;
  par[u] = -1;
  d[u] = 0;
  Q.push(u);
  vector<int> save;
  int res = 1e9;
  while (!Q.empty()) {
    int u = Q.front();
    save.push_back(u);
    Q.pop();
    bool flag = 1;
    for (int v : adj[u])
      if (d[v] == -1) {
        d[v] = d[u] + 1;
        par[v] = u;
        Q.push(v);
      } else {
        if (v == par[u] && flag)
          flag = 0;
        else
          res = min(res, d[u] + d[v] + 1);
      }
  }
  for (int i : save) d[i] = -1;
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    vector<int> p;
    for (int j = 2; j * j <= x; ++j)
      if (x % j == 0) {
        int cnt = 0;
        while (x % j == 0) ++cnt, x /= j;
        if (cnt & 1) p.push_back(j);
      }
    if (x > 1) p.push_back(x);
    if (p.empty()) {
      cout << 1;
      return 0;
    }
    if ((int)p.size() == 1)
      adj[1].push_back(p[0]), adj[p[0]].push_back(1);
    else
      adj[p[0]].push_back(p[1]), adj[p[1]].push_back(p[0]);
  }
  int res = 1e9;
  memset(d, -1, sizeof d);
  for (int i = 1; i <= 1000; ++i) res = min(res, bfs(i));
  if (res == 1e9) res = -1;
  cout << res;
}