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 + 5;
const int mod = 1e9 + 7;
long long qpow(long long a, long long b) {
  long long res = 1;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
int n;
vector<int> v[maxn];
map<pair<int, int>, int> mp;
vector<int> arry;
int vis[maxn], dist[maxn], a[maxn], pre[maxn];
int ans;
void bfs(int st) {
  queue<int> q;
  pre[st] = 0;
  q.push(st);
  for (int i = 0; i < arry.size(); ++i) a[arry[i]] = 0, dist[arry[i]] = n + 1;
  a[st] = 1;
  dist[st] = 0;
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (int i = 0; i < v[now].size(); ++i) {
      int to = v[now][i];
      if (to == pre[now])
        continue;
      else if (a[to]) {
        ans = min(ans, dist[to] + dist[now] + 1);
      } else {
        pre[to] = now;
        dist[to] = dist[now] + 1;
        a[to] = 1;
        q.push(to);
      }
    }
  }
}
int main() {
  scanf("%d", &n);
  ans = n + 1;
  for (int i = 1; i <= n; ++i) {
    int a;
    scanf("%d", &a);
    vector<int> tmp;
    for (int j = 2; j * j <= a; ++j) {
      int cnt = 0;
      if (a % j == 0) {
        while (a % j == 0) {
          a /= j;
          cnt++;
        }
      }
      if (cnt & 1) tmp.push_back(j);
    }
    if (a > 1) tmp.push_back(a);
    if (tmp.empty()) {
      ans = 1;
      continue;
    }
    if (tmp.size() == 1) tmp.push_back(1);
    v[tmp[0]].push_back(tmp[1]);
    v[tmp[1]].push_back(tmp[0]);
    if ((++mp[make_pair(tmp[0], tmp[1])]) > 1) ans = min(ans, 2);
    if ((++mp[make_pair(tmp[1], tmp[0])]) > 1) ans = min(ans, 2);
    for (int j = 0; j < tmp.size(); ++j) {
      if (!vis[tmp[j]]) {
        arry.push_back(tmp[j]);
        vis[tmp[j]] = 1;
      }
    }
  }
  sort(arry.begin(), arry.end());
  for (int i = 0; i < arry.size(); ++i) {
    if (arry[i] > 1000) break;
    bfs(arry[i]);
  }
  if (ans == n + 1) ans = -1;
  cout << ans << endl;
  return 0;
}