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 long long int mxN = 1000001;
long long int n;
vector<long long int> adj[mxN];
long long int d[mxN + 1], par[mxN + 1];
long long int seive[mxN + 2] = {0};
long long int ans = 2e9;
void c_r_c() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
void cycle() {
  for (long long int i = 0; i <= 1000000; i++) {
    d[i] = (2e9);
  }
  for (long long int i = 1; i <= 1000; i++) {
    d[i] = 0;
    par[i] = -1;
    queue<long long int> q;
    vector<long long int> e;
    q.push(i);
    e.push_back(i);
    while (!q.empty()) {
      long long int v = q.front();
      q.pop();
      for (long long int u : adj[v]) {
        if (d[u] >= (1e9)) {
          d[u] = d[v] + 1;
          par[u] = v;
          q.push(u);
          e.push_back(u);
        } else if (u != par[v]) {
          ans = min(ans, d[u] + d[v] + 1);
        }
      }
    }
    for (long long int x : e) {
      d[x] = (2e9);
      par[x] = -1;
    }
  }
}
int32_t main() {
  c_r_c();
  cin >> n;
  vector<long long int> pr;
  for (long long int i = 2; i <= mxN; i++) {
    if (seive[i]) continue;
    for (long long int j = i; j <= mxN; j += i) {
      seive[j] = i;
    }
  }
  for (long long int i = 1, a; i <= n; i++) {
    cin >> a;
    vector<long long int> v;
    for (long long int j = a; j > 1;) {
      long long int t = 0;
      long long int val = seive[j];
      while (j > 1 and j % val == 0) {
        t ^= 1;
        j /= val;
      }
      if (t == 1) {
        v.push_back(val);
      }
    }
    if (v.size() == 0) {
      cout << 1 << endl;
      return 0;
    }
    while (v.size() < 2) {
      v.push_back(1);
    }
    adj[v[0]].push_back(v[1]);
    adj[v[1]].push_back(v[0]);
  }
  cycle();
  if (ans >= 1e9) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}