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 N = 1e5 + 100, K = 3e5 + 100, M = 1e6 + 100, MID = 1010;
vector<int> prs[M];
vector<int> g[K];
int sz, ans, dis[K];
map<int, int> mp;
bool ok[K];
int add(int p) {
  if (mp.count(p)) return mp[p];
  ok[sz] = p < MID;
  return mp[p] = sz++;
}
void sh_cyc(int rt) {
  for (int i = 0; i < sz; i++) dis[i] = 1e9;
  queue<int> q;
  dis[rt] = 0;
  q.push(rt);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (auto u : g[v])
      if (dis[u] > dis[v] + 1) {
        dis[u] = dis[v] + 1;
        q.push(u);
      } else if (dis[u] >= dis[v])
        ans = min(ans, dis[v] + dis[u] + 1);
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  ok[0] = true;
  sz = 1;
  for (int i = 2; i < M; i++)
    if (prs[i].empty())
      for (int j = i; j < M; j += i) prs[j].push_back(i);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int d;
    cin >> d;
    vector<int> cur = prs[d], v;
    for (auto p : cur) {
      int cnt = 0;
      while (d % p == 0) {
        d /= p;
        cnt++;
      }
      if (cnt & 1) v.push_back(p);
    }
    if (v.empty()) {
      cout << "1\n";
      return 0;
    }
    if (v.size() == 1) {
      int p = add(v[0]);
      g[p].push_back(0);
      g[0].push_back(p);
    } else {
      int p = add(v[0]), q = add(v[1]);
      g[p].push_back(q);
      g[q].push_back(p);
    }
  }
  ans = 1e9;
  for (int i = 0; i < sz; i++)
    if (ok[i]) sh_cyc(i);
  if (ans > N) ans = -1;
  cout << ans << "\n";
}