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;
vector<int> g[maxn];
vector<int> num;
int pre[maxn], dis[maxn], vis[maxn];
void divide(int x) {
  num.clear();
  int a = x;
  for (int i = 2; i * i <= x; i++) {
    if (a % i == 0) {
      int cnt = 0;
      while (a % i == 0) {
        a /= i;
        cnt ^= 1;
      }
      if (cnt) num.push_back(i);
    }
  }
  if (a > 1) num.push_back(a);
}
int bfs(int begin) {
  vector<int> use;
  queue<int> q;
  q.push(begin);
  dis[begin] = 0, pre[begin] = 0;
  use.push_back(begin);
  int ans = 1e9;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = 0; i < g[x].size(); i++) {
      int t = g[x][i];
      if (t == pre[x]) continue;
      if (dis[t] != -1) {
        ans = dis[x] + dis[t] + 1;
        break;
      }
      dis[t] = dis[x] + 1;
      pre[t] = x;
      q.push(t);
      use.push_back(t);
    }
    if (ans != 1e9) break;
  }
  for (int i = 0; i < use.size(); i++) {
    dis[use[i]] = -1;
    pre[use[i]] = 0;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  int ans = 1e9, tmp = 1e9;
  memset(dis, -1, sizeof(dis));
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    if (vis[x] == 1) tmp = 2;
    vis[x] = 1;
    divide(x);
    if (num.size() == 2) {
      g[num[0]].push_back(num[1]);
      g[num[1]].push_back(num[0]);
    } else if (num.size() == 1) {
      g[num[0]].push_back(1);
      g[1].push_back(num[0]);
    } else
      ans = 1;
  }
  ans = min(ans, tmp);
  for (int i = 1; i <= 1000; i++) {
    ans = min(ans, bfs(i));
  }
  if (ans == 1e9)
    cout << -1 << '\n';
  else
    cout << ans << '\n';
  return 0;
}