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 a[100005], vis[1000005], last;
vector<pair<int, int> > adj[1000005], edges;
int solve(int ss) {
  if (adj[ss].empty()) return 1e9;
  queue<pair<int, int> > q;
  q.push(pair<int, int>(ss, -1));
  memset(vis, -1, sizeof vis);
  vis[ss] = 0;
  int res = 1e9;
  while (!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    int u = p.first, back = p.second;
    for (pair<int, int> t : adj[u]) {
      int idx = t.first, v = t.second;
      if (vis[v] == -1) {
        vis[v] = vis[u] + 1;
        q.push({v, idx});
      } else if (idx != back)
        res = min(res, vis[u] + vis[v] + 1);
    }
  }
  return res;
}
void add_edge(int u, int v) {
  adj[u].push_back(pair<int, int>(last, v));
  adj[v].push_back(pair<int, int>(last, u));
  edges.push_back(pair<int, int>(u, v));
  last++;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    vector<int> primes;
    cin >> a[i];
    int x = a[i];
    int root = sqrt(x);
    if (root * root == x) {
      cout << 1 << endl;
      return 0;
    }
    for (int j = 2; j <= root; j++)
      if (x % j == 0) {
        int cnt = 0;
        while (x % j == 0) x /= j, cnt++;
        if (cnt % 2 == 1) primes.push_back(j);
      }
    if (x != 1) primes.push_back(x);
    if (primes.size() == 1) primes.push_back(1);
    int u = primes[0], v = primes[1];
    add_edge(u, v);
  }
  int res = 1e9;
  for (int i = 1; i <= 1e3; i++) res = min(res, solve(i));
  if (res == 1e9)
    cout << -1 << endl;
  else
    cout << res << endl;
  return 0;
}