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 = 1e6 + 5;
int n;
int a[N];
vector<int> s;
bool vis[N], use[N];
int d[N];
vector<pair<long long, int> > g[N];
vector<pair<long long, int> > e;
int bfs(int s) {
  for (int i = (1); i < (N - 2); i++) d[i] = n + 1, vis[i] = use[i] = false;
  vis[s] = true, d[s] = 0;
  queue<int> q;
  q.push(s);
  int ans = n + 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto it : g[u]) {
      int v = it.first;
      if (!vis[v]) {
        use[it.second] = true;
        vis[v] = true;
        d[v] = d[u] + 1;
        q.push(v);
      }
    }
  }
  for (int i = (0); i < ((int)e.size()); i++) {
    if (use[i + 1]) continue;
    ans = min(ans, d[e[i].first] + d[e[i].second] + 1);
  }
  return ans;
}
int cnt[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = (1); i < (n + 1); i++) {
    cin >> a[i];
    s.clear();
    cnt[a[i]]++;
    for (int j = 2; j * j <= a[i]; ++j) {
      if (a[i] % j == 0) {
        int cc = 0;
        while (a[i] % j == 0) a[i] /= j, cc++;
        if (cc & 1) s.push_back(j);
      }
    }
    if (a[i] > 1) s.push_back(a[i]);
    if ((int)s.size() == 0) {
      cout << 1;
      return 0;
    }
    if ((int)s.size() == 1)
      g[1].push_back(pair<long long, int>(s[0], i)),
          g[s[0]].push_back(pair<long long, int>(1, i)),
          e.push_back(pair<long long, int>(1, s[0]));
    else
      g[s[0]].push_back(pair<long long, int>(s[1], i)),
          g[s[1]].push_back(pair<long long, int>(s[0], i)),
          e.push_back(pair<long long, int>(s[0], s[1]));
  }
  for (int i = (1); i < (N); i++)
    if (cnt[i] > 1) {
      cout << 2;
      return 0;
    }
  int ans = n + 1;
  for (int i = 1; i <= 1000; ++i) ans = min(ans, bfs(i));
  if (ans == n + 1) ans = -1;
  cout << ans << "\n";
  return 0;
}