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 = 1000001, maxp = 168, inf = 0x3f3f3f3f;
int n, a[maxn];
int pr[maxp] = {2,   3,   5,   7,   11,  13,  17,  19,  23,  29,  31,  37,  41,
                43,  47,  53,  59,  61,  67,  71,  73,  79,  83,  89,  97,  101,
                103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167,
                173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239,
                241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313,
                317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397,
                401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467,
                479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569,
                571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643,
                647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733,
                739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823,
                827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911,
                919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997};
map<int, int> m;
vector<int> unq;
vector<pair<int, int> > adj[maxn << 1];
vector<pair<pair<int, int>, int> > E;
queue<pair<int, int> > q;
int dist[maxn << 1];
int main() {
  scanf("%d", &n);
  for (int i = 0, u, v; i < n; i++) {
    scanf("%d", &a[i]);
    int tmp = a[i];
    m.clear();
    for (int j = 0; j < maxp && pr[j] * pr[j] <= tmp; j++)
      if (tmp % pr[j] == 0) tmp /= pr[j], m[pr[j]]++, j--;
    if (tmp > 1) m[tmp]++;
    if (!m.empty() && m.begin()->second % 2 == 0) m.erase(m.begin());
    if (!m.empty()) {
      map<int, int>::iterator it = m.end();
      it--;
      if (it->second % 2 == 0) m.erase(it);
    }
    if (m.size() == 2) {
      u = m.begin()->first;
      m.erase(m.begin());
      v = m.begin()->first;
      E.push_back({{u, v}, i});
      unq.push_back(u);
      unq.push_back(v);
    } else if (m.size() == 1) {
      u = m.begin()->first;
      E.push_back({{u, 1}, i});
      unq.push_back(u);
      unq.push_back(1);
    } else
      return printf("1\n"), 0;
  }
  sort(unq.begin(), unq.end());
  unq.erase(unique(unq.begin(), unq.end()), unq.end());
  m.clear();
  for (int i = 0; i < unq.size(); i++) m[unq[i]] = i + 1;
  for (pair<pair<int, int>, int> e : E)
    adj[m[e.first.first]].push_back({m[e.first.second], e.second}),
        adj[m[e.first.second]].push_back({m[e.first.first], e.second});
  int ans = inf;
  for (int i = 0; i < unq.size() && unq[i] <= 1000; i++) {
    memset(dist, 0, sizeof dist);
    for (pair<int, int> nxt : adj[i + 1]) q.push(nxt), dist[nxt.first] = 1;
    while (!q.empty()) {
      pair<int, int> cur = q.front();
      q.pop();
      for (pair<int, int> nxt : adj[cur.first])
        if (nxt.second != cur.second)
          if (dist[nxt.first] || nxt.first == i + 1)
            ans = min(ans, dist[cur.first] + dist[nxt.first] + 1);
          else
            q.push(nxt), dist[nxt.first] = dist[cur.first] + 1;
    }
  }
  if (ans == inf)
    printf("-1\n");
  else
    printf("%d\n", ans);
}