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 n;
int a[100005];
int b[1000005];
int bb[1000005];
vector<int> adj[1000005];
bool p[1000005];
int smpf[1000005];
int dist[1000005];
vector<int> vals;
queue<int> q;
int par[1000005];
void add_edge(int x) {
  int p = smpf[x];
  int cnt = 0;
  while (x % p == 0) x /= p, cnt++;
  cnt %= 2;
  int cnt1 = 0;
  int p1 = smpf[x];
  while (x > 1 && x % p1 == 0) x /= p1, cnt1++;
  cnt1 %= 2;
  if (cnt == 0) p = 1;
  if (cnt1 == 0) p1 = 1;
  adj[p].push_back(p1);
  adj[p1].push_back(p);
  vals.push_back(p);
  vals.push_back(p1);
  bb[p * p1]++;
}
int get(int s) {
  int an = n + 1;
  for (auto j : vals) dist[j] = 1e9;
  dist[s] = 0;
  q.push(s);
  while (q.size()) {
    int i = q.front();
    q.pop();
    for (auto j : adj[i]) {
      if (dist[j] > dist[i] + 1) {
        dist[j] = dist[i] + 1;
        par[j] = i;
        q.push(j);
      } else if (dist[i] + dist[j] + 1 > 2 && par[i] != j) {
        an = min(an, dist[i] + dist[j] + 1);
      }
    }
  }
  return an;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  smpf[1] = 1;
  for (long long int i = 2; i <= 1000000; i++) {
    if (p[i] == 0) {
      smpf[i] = i;
      for (long long int j = i * i; j <= 1000000; j += i)
        if (p[j] == 0) smpf[j] = i, p[j] = 1;
    }
  }
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i], b[a[i]]++;
  for (int i = 1; i <= 1000; i++)
    if (b[i * i]) return cout << 1 << '\n', 0;
  if (*max_element(b + 1, b + 1000000 + 1) >= 2) return cout << 2 << '\n', 0;
  for (int i = 1; i <= 1000000; i++)
    if (b[i]) add_edge(i);
  if (*max_element(bb + 1, bb + 1000000 + 1) >= 2) return cout << 2 << '\n', 0;
  sort(vals.begin(), vals.end());
  vals.resize(unique(vals.begin(), vals.end()) - vals.begin());
  int ans = n + 1;
  for (auto j : vals)
    if (j <= 1000) ans = min(ans, get(j));
  if (ans == n + 1) ans = -1;
  cout << ans << '\n';
  return 0;
}