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 + 100;
const int inf = 0x3f3f3f3f;
int a[maxn];
int p[maxn];
long long dis[maxn];
vector<int> v, e[maxn];
int pm[maxn], pid[maxn];
int ptop;
void init() {
  int n = maxn - 1;
  p[0] = 1;
  pm[1] = 1;
  pid[1] = 0;
  for (int i = 2; i <= n; ++i) {
    if (!pm[i]) {
      p[++ptop] = i;
      pm[i] = i;
      pid[i] = ptop;
    }
    for (int j = 1; j <= ptop; ++j) {
      int t = i * p[j];
      if (t > n) break;
      pm[t] = p[j];
      if (i % p[j] == 0) break;
    }
  }
}
int fj(int x) {
  int d = 1;
  while (x > 1) {
    int p = pm[x];
    x /= p;
    if (d % p == 0) {
      d /= p;
      continue;
    }
    d *= p;
  }
  return d;
}
int main() {
  int n;
  scanf("%d", &n);
  init();
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    int a = 1, b = 1;
    while (x != 1) {
      int t = pm[x];
      if (x % (t * t) == 0) {
        x /= (t * t);
      } else {
        x /= t;
        if (a == 1)
          a = t;
        else
          b = t;
      }
    }
    e[a].push_back(b);
    e[b].push_back(a);
    v.push_back(a);
    v.push_back(b);
  }
  sort(v.begin(), v.end());
  int sz = unique(v.begin(), v.end()) - v.begin();
  long long ans = inf;
  for (int x : v) {
    if (x > 1000) break;
    queue<int> q;
    for (int i = 0; i < sz; i++) {
      dis[v[i]] = inf;
    }
    dis[x] = 0;
    q.push(x);
    while (!q.empty()) {
      int t = q.front();
      q.pop();
      for (int to : e[t]) {
        if (dis[to] > dis[t] + 1) {
          dis[to] = dis[t] + 1;
          q.push(to);
        } else if (dis[to] >= dis[t]) {
          ans = min(ans, dis[to] + dis[t] + 1);
        }
      }
    }
  }
  if (ans >= inf) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}