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 MOD = 1000000007;
const double PI = atan(1.0) * 4;
vector<int> sieve;
vector<int> primes;
map<int, int> idx;
vector<vector<pair<int, int> > > to;
vector<bool> sqr;
void yo() {
  int bound = 1000000;
  for (int i = 2; i <= bound; i++) {
    if (sieve[i] == 0) {
      idx[i] = (int)primes.size();
      primes.push_back(i);
      for (int j = i; j <= bound; j += i) {
        if (sieve[j] == 0) sieve[j] = i;
      }
    }
  }
}
int main() {
  int n;
  idx[1] = (int)primes.size();
  primes.push_back(1);
  sieve.resize(1000005);
  yo();
  cin >> n;
  to.resize((int)primes.size());
  sqr.resize(1000005);
  for (int i = 0; i < (1000); i++) sqr[i * i] = true;
  for (int i = 0; i < (n); i++) {
    int x;
    cin >> x;
    if (sqr[x]) {
      cout << 1;
      return 0;
    }
    vector<int> divs;
    while (x > 1) {
      int cnt = 0;
      int k = sieve[x];
      while (x % k == 0) {
        cnt++;
        x /= k;
      }
      if (cnt % 2 == 1) divs.push_back(idx[k]);
    }
    if ((int)divs.size() == 1) {
      to[idx[1]].push_back({divs[0], i});
      to[divs[0]].push_back({idx[1], i});
    }
    if ((int)divs.size() == 2) {
      to[divs[1]].push_back({divs[0], i});
      to[divs[0]].push_back({divs[1], i});
    }
  }
  int ans = 1e9;
  queue<int> q;
  bool vis[100000];
  int dis[100000];
  bool mark[100005];
  for (auto &p : primes) {
    if (p >= 1000) break;
    memset(vis, 0, sizeof vis);
    memset(dis, 0, sizeof dis);
    memset(mark, 0, sizeof mark);
    int src = idx[p];
    q.push(src);
    dis[src] = 0;
    vis[src] = 1;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (auto &vx : to[u]) {
        int v = vx.first;
        if (!vis[v]) {
          q.push(v);
          mark[vx.second] = 1;
          vis[v] = 1;
          dis[v] = dis[u] + 1;
        } else if (!mark[vx.second])
          ans = min(ans, dis[u] + 1 + dis[v]);
      }
    }
  }
  cout << ((ans == 1e9) ? -1 : ans);
  return 0;
}