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 int64_t M1 = 998244353;
const int64_t M2 = 1000000007;
mt19937 rng((uint64_t)chrono::steady_clock::now().time_since_epoch().count());
void solve() {
  int64_t n;
  cin >> n;
  vector<int64_t> a(n);
  vector<vector<int64_t>> factors(1e6 + 1), node(1e6 + 1);
  for (int64_t i = 2; i <= 1e6; i++)
    if (factors[i].empty()) {
      for (int64_t j = i; j <= 1e6; j += i) factors[j].push_back(i);
    }
  for (int64_t i = 0; i < n; i++) {
    int64_t x;
    cin >> x;
    vector<int64_t> v;
    int64_t y = x;
    for (int64_t d : factors[x]) {
      int64_t cnt = 0;
      while (y % d == 0) {
        cnt ^= 1;
        y /= d;
      }
      if (cnt) v.push_back(d);
    }
    if (v.empty()) {
      cout << 1 << "\n";
      return;
    } else if ((int64_t)v.size() == 1) {
      node[1].push_back(v[0]);
      node[v[0]].push_back(1);
    } else {
      node[v[0]].push_back(v[1]);
      node[v[1]].push_back(v[0]);
    }
  }
  vector<int64_t> dis(1e6 + 1, M1), done;
  int64_t ans = M1 * M1;
  for (int64_t i = 1; i <= 1000; i++) {
    queue<int64_t> q;
    q.push(i);
    done.push_back(i);
    dis[i] = 0;
    while (!q.empty()) {
      int64_t u = q.front();
      q.pop();
      for (int64_t v : node[u]) {
        if (dis[v] == M1) {
          dis[v] = dis[u] + 1;
          q.push(v);
          done.push_back(v);
        } else {
          if (dis[v] >= dis[u]) {
            ans = min(ans, dis[u] + dis[v] + 1);
            while (!q.empty()) {
              q.pop();
            }
            break;
          }
        }
      }
    }
    while (!done.empty()) {
      dis[done.back()] = M1;
      done.pop_back();
    }
  }
  cout << (ans == M1 * M1 ? -1 : ans) << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
}