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;
int n;
vector<int> prime;
bool p[1000000];
int in[2];
vector<int> link[1000010];
int mx, ans;
int dis[1000010];
int vis[1000010], ptr;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  prime.emplace_back(1);
  prime.emplace_back(2);
  for (int i = 3; i < 1000000; i++) {
    if (p[i]) continue;
    for (int j = i * 2; j < 1000000; j += i) p[j] = 1;
    prime.emplace_back(i);
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    mx = max(mx, x);
    in[0] = in[1] = -1;
    for (int j = 1; prime[j] * prime[j] <= x; j++) {
      if (x % prime[j]) continue;
      bool add = 0;
      while (x % prime[j] == 0) {
        add ^= 1;
        x /= prime[j];
      }
      if (add) {
        in[1] = in[0];
        in[0] = prime[j];
      }
    }
    if (x > 1) {
      in[1] = in[0];
      in[0] = x;
    }
    if (in[1] != -1) {
      link[in[0]].emplace_back(in[1]);
      link[in[1]].emplace_back(in[0]);
    } else if (in[0] != -1) {
      link[1].emplace_back(in[0]);
      link[in[0]].emplace_back(1);
    } else {
      cout << "1\n";
      return 0;
    }
  }
  ans = 1e9;
  for (int i = 0; prime[i] * prime[i] <= mx; i++) {
    dis[prime[i]] = 0;
    queue<pair<int, int>> q;
    q.push({prime[i], prime[i]});
    vis[prime[i]] = ++ptr;
    while (!q.empty()) {
      auto cur = q.front();
      q.pop();
      bool from = 0;
      for (auto k : link[cur.first]) {
        if (!from && k == cur.second) {
          from = 1;
          continue;
        }
        if (vis[k] == ptr) {
          ans = min(ans, dis[cur.first] + dis[k] + 1);
          break;
        } else {
          vis[k] = ptr;
          dis[k] = dis[cur.first] + 1;
          q.push({k, cur.first});
        }
      }
    }
  }
  cout << (ans == 1e9 ? -1 : ans) << '\n';
  return 0;
}