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 INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
int dist[78499], par[78499], sieve[1000010];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> primes;
  primes.push_back(1);
  for (long long i = 2; i <= 1e6; i++)
    if (sieve[i] == 0) {
      primes.push_back(i);
      sieve[i] = i;
      for (long long j = i * i; j <= 1e6; j += i) sieve[j] = i;
    }
  map<int, int> primeid;
  for (int i = 0; i < primes.size(); i++) primeid[primes[i]] = i;
  for (int& ai : a) {
    cin >> ai;
    map<int, int> factors;
    while (ai != 1) {
      factors[sieve[ai]]++;
      ai /= sieve[ai];
    }
    int left = 1;
    for (auto [b, times] : factors)
      if (times % 2 == 1) left *= b;
    ai = left;
  }
  map<int, int> test;
  for (auto u : a) test[u]++;
  int ans = INF;
  for (auto [u, times] : test) {
    if (u == 1)
      ans = 1;
    else if (times > 1)
      ans = min(ans, 2);
  }
  if (ans < INF) {
    cout << ans << '\n';
    exit(0);
  }
  vector<vector<int>> g(primes.size());
  for (int i = 0; i < n; i++) {
    int ida = primeid[sieve[a[i]]], idb = primeid[a[i] / sieve[a[i]]];
    g[ida].push_back(idb);
    g[idb].push_back(ida);
  }
  auto girth = [&](int x) {
    memset(dist, -1, sizeof dist);
    memset(par, -1, sizeof par);
    queue<int> q;
    q.push(x);
    dist[x] = 0;
    while (q.size()) {
      int ai = q.front();
      q.pop();
      for (auto b : g[ai])
        if (par[ai] != b) {
          if (dist[b] == -1) {
            dist[b] = dist[ai] + 1;
            q.push(b);
            par[b] = ai;
          } else
            return dist[ai] + dist[b] + 1;
        }
    }
    return INF;
  };
  for (int i = 0; i < primes.size(); i++)
    if (primes[i] <= 1000) {
      ans = min(ans, girth(i));
    }
  cout << (ans == INF ? -1 : ans) << '\n';
  return 0;
}