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 = 1e6 + 14, sq = 1e3;
int n;
vector<int> pr[maxn];
int cnt(int x, int p) {
  int cnt = 0;
  while (x % p == 0) cnt++, x /= p;
  return cnt;
}
vector<int> g[maxn];
vector<int> smalls[maxn];
int d[maxn], par[maxn];
int ans = INT_MAX;
void adde(int v, int u) {
  g[v].push_back(u);
  g[u].push_back(v);
}
void bfs(int source) {
  fill(d, d + maxn, INT_MAX);
  queue<int> q;
  d[source] = 0;
  q.push(source);
  while (q.size()) {
    int v = q.front();
    q.pop();
    int cp = 0;
    for (auto u : g[v])
      if (d[u] > d[v] + 1) {
        d[u] = d[v] + 1;
        par[u] = v;
        q.push(u);
      } else if (u != par[v] || cp++)
        ans = min(ans, d[v] + d[u] + 1);
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  srand(time(0));
  for (int i = 2; i < maxn; i++)
    if (pr[i].empty())
      for (int j = i; j < maxn; j += i) pr[j].push_back(i);
  cin >> n;
  while (n--) {
    int x;
    cin >> x;
    int sq = sqrt(x);
    if (sq * sq == x)
      return cout << "1\n", 0;
    else if (pr[x].size() == 1)
      adde(1, pr[x][0]);
    else {
      long long p = pr[x][0], q = pr[x][1];
      if (p * q == x)
        adde(p, q);
      else if (cnt(x, p) == 1)
        adde(1, p);
      else
        adde(1, q);
    }
  }
  for (int i = 0; i < sq; i++)
    if (pr[i].size() < 2) bfs(i);
  cout << (ans == INT_MAX ? -1 : ans) << '\n';
}