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;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
const int N = 1e5 + 10;
int n, cnt[1000010];
vi ps[N];
vi factor(int x) {
  vi pr;
  for (int i = 2; i * i <= x; ++i)
    if (x % i == 0) {
      pr.push_back(i);
      while (x % i == 0) ++cnt[i], x /= i;
    }
  if (x != 1) pr.push_back(x), ++cnt[x];
  vi ans;
  for (auto p : pr) {
    if (cnt[p] & 1) ans.push_back(p);
    cnt[p] = 0;
  }
  return ans;
}
vector<pii> g[1000010];
vi pr;
int d[1000010];
int ans = 1919810;
struct node {
  int u, d, lst;
};
void bfs(int s) {
  for (auto p : pr) d[p] = -1;
  d[s] = 0;
  queue<node> q;
  q.push({s, 0, 0});
  while (q.size()) {
    node nd = q.front();
    q.pop();
    int u = nd.u, lst = nd.lst;
    for (auto e : g[u]) {
      int v = e.first, eid = e.second;
      if (eid == lst) continue;
      if (d[v] == -1) {
        d[v] = d[u] + 1;
        q.push({v, d[v], eid});
      } else {
        ans = min(ans, d[u] + d[v] + 1);
      }
    }
  }
  int p1 = 0, p2 = 0;
  int mn1 = 1919810, mn2 = 1919810;
  for (auto p : pr)
    if (d[p] != -1 && cnt[p]) {
      if (d[p] <= mn1) {
        mn2 = mn1, mn1 = d[p];
        p2 = p1, p1 = p;
      } else if (d[p] <= mn2) {
        mn2 = d[p];
        p2 = p;
      }
    }
  ans = min(ans, mn1 + mn2 + 2);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    ps[i] = factor(x);
  }
  bool flg1 = 0, flg2 = 0;
  for (int i = 1; i <= n; ++i) {
    int sz = (int)ps[i].size();
    for (auto p : ps[i]) pr.push_back(p);
    if (sz == 0) {
      flg1 = 1;
    } else if (sz == 1) {
      ++cnt[ps[i][0]];
      if (cnt[ps[i][0]] >= 2) {
        flg2 = 1;
      }
    } else {
      int u = ps[i][0], v = ps[i][1];
      g[u].push_back(make_pair(v, i)), g[v].push_back(make_pair(u, i));
    }
  }
  if (flg1) {
    cout << "1\n";
    return 0;
  }
  if (flg2) {
    cout << "2\n";
    return 0;
  }
  sort(pr.begin(), pr.end());
  pr.erase(unique(pr.begin(), pr.end()), pr.end());
  for (auto p : pr)
    if (p <= 1000) bfs(p);
  if (ans != 1919810)
    cout << ans << '\n';
  else
    cout << "-1\n";
  return 0;
}