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 INF = 1e9;
const int N = 1000002;
int p[N], d[N], n;
vector<int> G[N], idx;
int q[N];
int bfs(int xx) {
  int ans = INF, l = 0, r = 0;
  q[r++] = xx;
  for (auto u : idx) d[u] = -1;
  d[xx] = 0;
  p[xx] = -1;
  while (l < r) {
    int x = q[l++];
    for (auto u : G[x])
      if (u != p[x]) {
        if (d[u] == -1)
          d[u] = d[x] + 1, q[r++] = u, p[u] = x;
        else
          ans = min(ans, 1 + d[u] + d[x]);
      }
  }
  return ans;
}
vector<int> f(int &x) {
  vector<int> ans;
  int y = 1;
  while (x > 1) {
    int r = p[x], cnt = 0;
    while (x % r == 0) cnt++, x /= r;
    if (cnt & 1) ans.push_back(r), y *= r;
  }
  x = y;
  return ans;
}
int main() {
  set<int> s;
  for (int i = 2; i * i < N; i++)
    if (!p[i])
      for (int j = i * i; j < N; j += i) p[j] = i;
  for (int i = 1; i < N; i++)
    if (!p[i]) p[i] = i;
  cin >> n;
  for (int i = 0, x; i < n; i++) {
    cin >> x;
    vector<int> tmp = f(x);
    if (x == 1) return cout << 1 << endl, 0;
    s.insert(x);
    if (tmp.size() == 1) tmp.push_back(1);
    idx.push_back(tmp[0]);
    idx.push_back(tmp[1]);
    G[tmp[0]].push_back(tmp[1]);
    G[tmp[1]].push_back(tmp[0]);
  }
  if (s.size() != n) return cout << 2 << endl, 0;
  sort(idx.begin(), idx.end());
  idx.resize(unique(idx.begin(), idx.end()) - idx.begin());
  int ans = INF;
  for (auto u : idx)
    if (u <= 1000) ans = min(ans, bfs(u));
  if (ans == INF) ans = -1;
  cout << ans << endl;
}