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 = 2e9 + 5;
const long long INF = 8e18;
const int maxn = 1e6 + 5;
vector<int> e[maxn];
set<int> s, st;
int n, ans = inf;
int dis[maxn], q[maxn];
bool vis[maxn];
inline void init() {
  cin >> n;
  bool ok = 0;
  for (int i = 0; i < n; ++i) {
    int xx;
    cin >> xx;
    int x = 1, y = 1, m = sqrt(xx);
    for (int fac = 2; fac <= m; ++fac) {
      if (xx % fac == 0) {
        int cnt = 0;
        while (xx % fac == 0) {
          xx /= fac;
          ++cnt;
        }
        if (cnt & 1) {
          if (x == 1)
            x = fac;
          else
            y = fac;
        }
      }
    }
    if (xx) y = xx;
    if (x == 1 && y == 1) {
      cout << 1 << '\n';
      exit(0);
    }
    int ff = x * y;
    if (s.count(ff)) {
      ok = 1;
    }
    s.insert(ff);
    st.insert(x);
    st.insert(y);
    e[x].push_back(y);
    e[y].push_back(x);
  }
  if (ok) {
    cout << 2 << '\n';
    exit(0);
  }
}
inline void bfs(int u) {
  int uu = u;
  for (auto x : st) vis[x] = 0, dis[x] = inf;
  vis[u] = 1, dis[u] = 0;
  int t = 0;
  q[++t] = u;
  for (int i = 1; i <= t; ++i) {
    int u = q[i];
    vis[u] = 0;
    for (auto v : e[u]) {
      if (dis[v] > dis[u] + 1) {
        dis[v] = dis[u] + 1;
        q[++t] = v;
        vis[v] = 1;
      } else if (vis[v])
        ans = min(ans, dis[u] + dis[v] + 1);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  init();
  for (int i = 1; i <= 1000; ++i) {
    if (!e[i].empty()) bfs(i);
  }
  if (ans != inf)
    cout << ans << '\n';
  else
    cout << -1 << '\n';
  return 0;
}