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;
long long gcd(long long a, long long b);
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
vector<long long> v[1000005];
long long dis[1000005];
long long par[1000005];
long long che[1000005];
void sieve() {
  for (long long i = 2; i < 1000005; i++) che[i] = i;
  for (long long i = 2; i < 1000005; i++) {
    if (che[i] == i) {
      for (long long j = i; j < 1000005; j += i) che[j] = i;
    }
  }
}
void solve() {
  sieve();
  long long ans = 1000000007;
  long long n;
  cin >> n;
  long long a;
  for (long long i = 0; i < n; i++) {
    cin >> a;
    vector<long long> vv;
    while (a > 1) {
      auto it = find(vv.begin(), vv.end(), che[a]);
      if (it != vv.end()) {
        vv.erase(it);
      } else {
        vv.push_back(che[a]);
      }
      a /= che[a];
    }
    if (vv.size() == 0) {
      cout << "1" << endl;
      return;
    } else if (vv.size() == 1) {
      v[1].push_back(vv[0]);
      v[vv[0]].push_back(1);
    } else {
      v[vv[0]].push_back(vv[1]);
      v[vv[1]].push_back(vv[0]);
    }
  }
  for (long long i = 1; i <= 1000; i++) {
    queue<long long> q;
    memset(dis, -1, sizeof dis);
    par[i] = 0;
    dis[i] = 0;
    q.push(i);
    while (!q.empty()) {
      long long cur = q.front();
      q.pop();
      for (auto it : v[cur]) {
        if (dis[it] == -1) {
          par[it] = cur;
          dis[it] = dis[cur] + 1;
          q.push(it);
        } else if (par[cur] != it) {
          ans = min(ans, dis[cur] + dis[it] + 1);
        }
      }
    }
  }
  if (!(ans ^ 1000000007)) {
    cout << "-1" << endl;
    return;
  }
  cout << ans << endl;
}
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}