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 maxn = 100010;
const int maxa = 1000010;
int n, a[maxn], maxx;
vector<int> prime;
bool isp[maxa];
int pr_tot;
bool changed[maxa];
vector<int> p[maxa];
int h[maxa], en;
struct Edge {
  int u;
  int v;
  int next;
};
Edge e[2 * maxn];
int ans;
int dis[maxa];
void find_prime(int x) {
  fill(isp + 2, isp + x + 1, true);
  for (int i = 2; i <= x; i++) {
    if (isp[i]) {
      prime.push_back(i);
      pr_tot++;
    }
    for (int j = 0; j < pr_tot && i * prime[j] <= x; j++) {
      isp[i * prime[j]] = false;
      if (i % prime[j] == 0) break;
    }
  }
  return;
}
void init(int x) {
  int var = x;
  for (int i = 2; i * i <= var; i++)
    if (x % i == 0) {
      int index = 0;
      while (x % i == 0) {
        x /= i;
        index++;
      }
      if (index % 2 == 1) p[var].push_back(i);
    }
  if (isp[x]) p[var].push_back(x);
  return;
}
void addedge(int u, int v) {
  en++;
  e[en].u = u;
  e[en].v = v;
  e[en].next = h[u];
  h[u] = en;
  return;
}
void bfs() {
  ans = INT_MAX;
  prime.insert(prime.begin(), 1);
  for (int i = 0; i <= pr_tot; i++) {
    if ((long long)prime[i] * prime[i] > maxx) break;
    queue<pair<int, int> > q;
    fill(dis + 1, dis + maxx + 1, INT_MAX);
    q.push(make_pair(prime[i], 0));
    dis[prime[i]] = 0;
    while (!q.empty()) {
      pair<int, int> tmp = q.front();
      q.pop();
      int u = tmp.first, fa = tmp.second;
      for (int j = h[u]; j != 0; j = e[j].next) {
        int v = e[j].v;
        if (v == fa) continue;
        if (dis[v] == INT_MAX && v != prime[i]) {
          dis[v] = dis[u] + 1;
          q.push(make_pair(v, u));
        } else {
          ans = min(ans, dis[u] + dis[v] + 1);
        }
      }
    }
  }
  if (ans == INT_MAX) ans = -1;
  return;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    maxx = max(maxx, a[i]);
  }
  find_prime(maxx);
  for (int i = 1; i <= n; i++) {
    if (!changed[a[i]]) init(a[i]);
    changed[a[i]] = true;
  }
  for (int i = 1; i <= n; i++) {
    if (p[a[i]].empty()) {
      cout << 1 << endl;
      return 0;
    }
    if (p[a[i]].size() == 1) p[a[i]].push_back(1);
    addedge(p[a[i]][0], p[a[i]][1]);
    addedge(p[a[i]][1], p[a[i]][0]);
  }
  bfs();
  cout << ans << endl;
  return 0;
}