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 N = (int)1e6 + 50, INF = (int)1e9;
int n, a[N];
vector<int> G[N];
map<int, int> sig;
map<pair<int, int>, int> dob;
int dis[N], pv[N];
int pm[N], pms;
int p[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  fill(p + 2, p + N, 1);
  for (int i = 2; i < N; i++) {
    if (p[i]) {
      pm[pms++] = i;
      for (int j = i * 2; j < N; j += i) p[j] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    int x = -1, y = -1;
    for (int d = 1; d * d <= a[i]; d++) {
      if (a[i] % d == 0) {
        if (p[d]) {
          if (x == -1)
            x = d;
          else
            y = d;
        }
        if (d * d != a[i] && p[a[i] / d]) {
          if (x == -1)
            x = a[i] / d;
          else
            y = a[i] / d;
        }
      }
    }
    int cx = 0, cy = 0;
    if (x != -1)
      while (a[i] % x == 0) cx = !cx, a[i] /= x;
    if (y != -1)
      while (a[i] % y == 0) cy = !cy, a[i] /= y;
    assert(a[i] == 1);
    if (!cx && !cy) {
      cout << 1 << endl;
      return 0;
    } else if (cx && cy) {
      G[x].push_back(y);
      G[y].push_back(x);
      dob[{x, y}]++;
      dob[{y, x}]++;
    } else {
      if (!cx) swap(x, y);
      G[x].push_back(0);
      G[0].push_back(x);
      sig[x] += 1;
    }
  }
  for (auto p : sig)
    if (p.second >= 2) {
      cout << 2 << endl;
      return 0;
    }
  for (auto p : dob)
    if (p.second >= 2) {
      cout << 2 << endl;
      return 0;
    }
  int res = INF;
  for (int s = 0; s <= 1000; s++) {
    if (s == 0 || p[s]) {
      dis[0] = INF;
      for (int i = 0; i < pms; i++) dis[pm[i]] = INF;
      queue<int> que;
      dis[s] = 0;
      que.push(s);
      pv[s] = -1;
      while (!que.empty()) {
        int v = que.front();
        que.pop();
        for (int nxt : G[v]) {
          if (dis[nxt] == INF) {
            dis[nxt] = dis[v] + 1;
            pv[nxt] = v;
            que.push(nxt);
          } else {
            if (nxt != pv[v]) res = min(res, dis[nxt] + dis[v] + 1);
          }
        }
      }
    }
  }
  if (res == INF) res = -1;
  cout << res << '\n';
}