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>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const long long maxn = (long long)1e6 + 5;
const long long mod = 998244353;
const long long inf = 0x3f3f3f3f;
long long T = 1;
vector<long long> prime;
bool vis[maxn];
vector<long long> v[maxn];
void add(long long x, long long y) {
  v[x].push_back(y);
  v[y].push_back(x);
}
long long dep[maxn];
long long ans = LLONG_MAX;
long long id[maxn];
void bfs(long long x) {
  memset(dep, inf, sizeof(dep));
  queue<pair<long long, long long> > q;
  q.push({x, 0});
  dep[x] = 0;
  while (!q.empty()) {
    pair<long long, long long> now = q.front();
    q.pop();
    for (auto &to : v[now.first]) {
      if (to == now.second) continue;
      if (dep[to] > 1e16) {
        dep[to] = dep[now.first] + 1;
        q.push({to, now.first});
      } else {
        ans = min(ans, dep[now.first] + dep[to] + 1);
      }
    }
  }
}
void solve() {
  prime.push_back(1);
  id[1] = 0;
  for (long long i = 2; i <= maxn - 1; ++i) {
    if (!vis[i]) {
      id[i] = prime.size();
      prime.push_back(i);
      for (long long j = i + i; j < maxn; j += i) vis[j] = true;
    }
  }
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; ++i) {
    long long x;
    cin >> x;
    long long y = -1, z = -1;
    for (long long j = 1; j < prime.size() && prime[j] * prime[j] <= x; ++j) {
      if (x % prime[j] == 0) {
        while (x % (prime[j] * prime[j]) == 0) x /= (prime[j] * prime[j]);
        if (x % prime[j] == 0) {
          if (y == -1)
            y = j;
          else
            z = j;
          x /= prime[j];
        }
      }
    }
    if (x > 1) {
      if (y == -1)
        y = id[x];
      else
        z = id[x];
    }
    if (y == -1) {
      cout << "1";
      return;
    }
    if (z == -1) {
      add(0, y);
    } else {
      add(y, z);
    }
  }
  for (long long i = 0;; ++i) {
    long long j = prime[i];
    if (j > 1000) break;
    bfs(i);
  }
  if (ans == LLONG_MAX)
    cout << -1;
  else
    cout << ans;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  while (T--) solve();
  return 0;
}