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 vis[1010101], mp[1010101], to0[101010];
vector<int> prime;
void sieve(int lim) {
  vis[1] = 1;
  for (int i = 2; i <= lim; ++i) {
    if (!vis[i]) vis[i] = i, prime.push_back(i);
    for (auto j : prime) {
      if (i * j > lim) break;
      vis[i * j] = j;
      if (i % j == 0) break;
    }
  }
  for (int i = 0; i < (int)prime.size(); ++i) mp[prime[i]] = i + 1;
}
int n, a[101010], ans = 0x3f3f3f3f;
vector<int> G[101010];
set<pair<int, int> > eds;
int main() {
  sieve(1000010);
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    int p1 = -1, p2 = -1;
    while (a[i] != 1) {
      int d = vis[a[i]], c = 0;
      while (a[i] % d == 0) a[i] /= d, c ^= 1;
      if (c == 0) continue;
      if (p1 == -1)
        p1 = mp[d];
      else if (p2 == -1)
        p2 = mp[d];
      else
        assert(false);
    }
    if (p2 == -1) {
      if (p1 == -1) {
        puts("1");
        exit(0);
      } else {
        if (to0[p1]) ans = min(ans, 2);
        to0[p1] = true;
        G[0].push_back(p1);
        G[p1].push_back(0);
      }
    } else {
      G[p1].push_back(p2);
      G[p2].push_back(p1);
      if (eds.count(pair<int, int>(min(p1, p2), max(p1, p2))))
        ans = min(ans, 2);
      eds.insert(pair<int, int>(min(p1, p2), max(p1, p2)));
    }
  }
  if (ans == 2) {
    puts("2");
    return 0;
  }
  for (int i = 1; i <= (int)prime.size(); ++i) {
    if (prime[i - 1] * prime[i - 1] > 1000000) break;
    vector<int> d(prime.size() + 1, 0x3f3f3f3f);
    d[i] = 0;
    queue<pair<int, int> > q;
    for (auto g : G[i]) d[g] = 1, q.emplace(g, i);
    while (!q.empty()) {
      auto [f, las] = q.front();
      q.pop();
      for (auto g : G[f])
        if (g != las) {
          if (d[g] == 0x3f3f3f3f) {
            d[g] = d[f] + 1;
            q.emplace(g, f);
          } else
            ans = min(ans, d[g] + d[f] + 1);
        }
    }
  }
  if (ans == 0x3f3f3f3f) ans = -1;
  printf("%d\n", ans);
  return 0;
}