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 = 1e6 + 5;
vi e[N];
vector<pii> factor(int x) {
  int up = sqrt(x), c;
  vector<pii> res;
  for (int i = 2; i <= up; ++i) {
    if (x % i == 0) {
      c = 0;
      while (x % i == 0) {
        x /= i, c++;
      };
      res.push_back({i, c});
    }
  }
  if (x != 1) res.push_back({x, 1});
  return res;
}
set<int> s;
int cnt[N], vis[N], dis[N];
int q[N];
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    auto d = factor(x);
    vi pr;
    for (auto p : d) {
      if (p.second % 2) pr.push_back(p.first), s.insert(p.first);
    }
    if (pr.empty()) {
      puts("1");
      return 0;
    } else if (pr.size() == 1) {
      e[pr[0]].push_back(1);
      e[1].push_back(pr[0]);
      s.insert(1);
    } else {
      e[pr[0]].push_back(pr[1]);
      e[pr[1]].push_back(pr[0]);
    }
  }
  vi x((s).begin(), (s).end());
  int ans = n + 1;
  for (auto d : x)
    if (d <= 1000) {
      for (auto p : x) vis[p] = 0, dis[p] = n + 1;
      queue<int> que;
      dis[d] = 0;
      que.push(d);
      vis[d] = 1e9;
      while (!que.empty()) {
        int u = que.front();
        que.pop();
        for (auto v : e[u]) {
          if (!vis[v]) {
            que.push(v);
            vis[v] = u;
            dis[v] = dis[u] + 1;
          } else if (vis[u] != v) {
            ans = min(ans, dis[u] + dis[v] + 1);
          }
        }
      }
    }
  if (ans == n + 1) {
    puts("-1");
  } else
    cout << ans << endl;
  return 0;
}