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 mod = 998244353;
const int INF = 1e9;
const int maxn = 1e6 + 10;
const double eps = 1e-8;
int add(int x, int y) {
  x += y;
  return x >= mod ? x - mod : x;
}
int sub(int x, int y) {
  x -= y;
  return x < 0 ? x + mod : x;
}
int mul(int x, int y) { return 1LL * x * y % mod; }
int dep[maxn], tot, ans;
vector<pair<int, int> > g[maxn];
queue<pair<int, int> > q;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  bool ok = false;
  for (int i = 1; i <= n; i++) {
    vector<int> fac;
    int x;
    cin >> x;
    for (int d = 2; d * d <= x; d++)
      if (x % d == 0) {
        int cnt = 0;
        while (x % d == 0) cnt++, x /= d;
        if (cnt & 1) fac.push_back(d);
      }
    if (x > 1) fac.push_back(x);
    if (fac.size() == 2) {
      int p = fac[0], q = fac[1];
      g[p].push_back(pair<int, int>{q, ++tot}),
          g[q].push_back(pair<int, int>{p, tot});
    } else if (fac.size() == 1) {
      int p = fac[0];
      g[p].push_back(pair<int, int>{1, ++tot}),
          g[1].push_back(pair<int, int>{p, tot});
    } else
      ok = true;
  }
  if (ok) {
    cout << 1 << endl;
    return 0;
  }
  ans = INF;
  fill(dep + 1, dep + 1000000 + 1, INF);
  for (int i = 1; i <= 1000; i++) {
    vector<int> save;
    dep[i] = 0, q.push(pair<int, int>{i, 0});
    while (!q.empty()) {
      pair<int, int> x = q.front();
      q.pop();
      int u = x.first, pre = x.second;
      save.push_back(u);
      for (auto e : g[u]) {
        int v = e.first, id = e.second;
        if (id == pre) continue;
        if (dep[v] == INF) {
          dep[v] = dep[u] + 1;
          q.push(pair<int, int>{v, id});
        } else
          ans = min(ans, dep[u] + dep[v] + 1);
      }
    }
    for (auto x : save) dep[x] = INF;
  }
  if (ans == INF)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}