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 = 1000000;
bool breakpoint[1000001] = {0};
vector<int> ar[1000001];
bool vis[1000001];
int dp[1000001];
int pra[1000001];
int bfs(int s) {
  int ans = 1e9;
  memset(vis, false, sizeof(vis));
  memset(dp, 0, sizeof(dp));
  memset(pra, 0, sizeof(pra));
  queue<int> ae;
  int i = -1;
  if (breakpoint[s]) i = 1;
  ae.push(s);
  vis[s] = true;
  dp[s] = 0;
  while (!ae.empty()) {
    int w = ae.front();
    ae.pop();
    for (auto it : ar[w]) {
      if (!vis[it]) {
        dp[it] = dp[w] + 1;
        pra[it] = w;
        vis[it] = true;
        ae.push(it);
        if (breakpoint[it]) {
          if (i == -1)
            i = dp[it] + 1;
          else
            ans = min(ans, dp[it] + 1 + i);
        }
      } else if (it != pra[w]) {
        ans = min(ans, dp[w] + dp[it] + 1);
      }
    }
  }
  return ans;
}
int solve() {
  int ans = 1e9;
  for (int x = 1; x <= 1000; x++) {
    if (ar[x].size() > 0) ans = min(ans, bfs(x));
  }
  return ans;
}
int lp[N + 1];
vector<int> pr;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  for (int i = 2; i <= N; ++i) {
    if (lp[i] == 0) {
      lp[i] = i;
      pr.push_back(i);
    }
    for (int j = 0; j < (int)pr.size() && pr[j] <= lp[i] && i * pr[j] <= N; ++j)
      lp[i * pr[j]] = pr[j];
  }
  int n;
  cin >> n;
  int a[n];
  int ans = 1e9;
  for (int i = (0); i != (n); i = (0) < (n) ? i + 1 : i - 1) cin >> a[i];
  for (int i = (0); i != (n); i = (0) < (n) ? i + 1 : i - 1) {
    vector<int> ae;
    while (a[i] > 1) {
      int g = lp[a[i]];
      int co = 0;
      while (a[i] % g == 0) {
        ++co;
        a[i] /= g;
      }
      if (co % 2 == 1) ae.push_back(g);
    }
    if (ae.size() == 0) {
      ans = 1;
      break;
    }
    if (ae.size() > 1) {
      ar[ae[0]].push_back(ae[1]);
      ar[ae[1]].push_back(ae[0]);
    } else {
      if (breakpoint[ae[0]])
        ans = min(ans, 2);
      else
        breakpoint[ae[0]] = true;
    }
  }
  if (ans > 2) ans = min(ans, solve());
  if (ans > 100000) ans = -1;
  cout << ans << "\n";
}