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 double pi = acos(-1.0);
const double eps = 1e-8;
const int mxn = 100033;
const int mxa = 1000003;
const int mod = 1e9 + 7;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) f = c == '-' ? -1 : 1, c = getchar();
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  return x * f;
}
inline long long gcd(long long a, long long b) {
  return b == 0 ? a : gcd(b, a % b);
}
long long ksm(long long a, long long b, long long mod) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}
long long inv2(long long a, long long mod) { return ksm(a, mod - 2, mod); }
void exgcd(long long a, long long b, long long &x, long long &y, long long &d) {
  if (!b) {
    d = a;
    x = 1;
    y = 0;
  } else {
    exgcd(b, a % b, y, x, d);
    y -= x * (a / b);
  }
}
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int n, a[mxn], res;
bool isnp[mxa];
int prime[mxa], id[mxa];
vector<int> g[mxa << 1];
void euler() {
  isnp[0] = isnp[1] = 1;
  for (int i = 2; i < mxa; ++i) {
    if (!isnp[i]) prime[++prime[0]] = i, id[i] = prime[0] + 1;
    for (int j = 1; j <= prime[0] && i * prime[j] < mxa; ++j) {
      isnp[i * prime[j]] = 1;
      if (i % prime[j] == 0) break;
    }
  }
}
void divide(int x) {
  int p[4] = {0}, k[4] = {0};
  for (int i = 1; i <= prime[0] && prime[i] * prime[i] <= x; ++i) {
    if (x % prime[i] == 0) {
      p[++p[0]] = prime[i];
      while (x % prime[i] == 0) k[p[0]] ^= 1, x /= prime[i];
      if (!k[p[0]]) p[0]--;
    }
  }
  if (x > 1) p[++p[0]] = x, k[p[0]] = 1;
  if (!p[0]) {
    cout << 1 << endl;
    exit(0);
  }
  if (p[0] == 1)
    g[1].push_back(id[p[1]]), g[id[p[1]]].push_back(1);
  else
    g[id[p[1]]].push_back(id[p[2]]), g[id[p[2]]].push_back(id[p[1]]);
}
int dis[mxa];
void bfs(int st) {
  memset((dis), (0x3f3f3f3f), sizeof((dis)));
  dis[st] = 0;
  queue<pair<int, int> > q;
  q.push(make_pair(st, 0));
  while (!q.empty()) {
    pair<int, int> t = q.front();
    q.pop();
    int u = t.first;
    for (auto v : g[u]) {
      if (v == t.second) continue;
      if (dis[v] == 0x3f3f3f3f) {
        dis[v] = dis[u] + 1;
        q.push(make_pair(v, u));
      } else
        res = min(res, dis[u] + dis[v] + 1);
    }
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  ;
  euler();
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) divide(a[i]);
  res = 0x3f3f3f3f;
  for (int i = 1; i <= 1000; ++i) bfs(i);
  if (res == 0x3f3f3f3f)
    cout << -1 << endl;
  else
    cout << res << endl;
  return 0;
}