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 maxn = 1e5 + 5;
int n, a[maxn], res[maxn][2], dis[maxn * 10];
bool has[maxn * 10];
char vis[maxn * 10];
vector<int> g[maxn * 10];
void d(int idx, int A) {
  int cnt = 0, top = 0;
  if (!(A & 1)) {
    while (!(A & 1)) {
      A >>= 1;
      ++cnt;
    }
    if (cnt & 1) res[idx][top++] = 2;
  }
  for (int i = 3; i * i <= A; i += 2) {
    cnt = 0;
    while (A % i == 0) {
      A /= i;
      ++cnt;
    }
    if (cnt & 1) {
      res[idx][top++] = i;
    }
  }
  if (A != 1) {
    res[idx][top++] = A;
  }
}
int bfs(int s) {
  int res = n + 1;
  queue<int> Q;
  Q.push(s);
  memset(vis, 0, sizeof(vis));
  memset(dis, 0, sizeof(dis));
  dis[s] = 1;
  while (!Q.empty()) {
    int cur = Q.front();
    Q.pop();
    vis[cur] = 2;
    for (int v : g[cur]) {
      if (vis[v] == 2)
        continue;
      else if (vis[v] == 1)
        res = min(res, dis[cur] + dis[v] - 1);
      else {
        vis[v] = 1;
        dis[v] = dis[cur] + 1;
        Q.push(v);
      }
    }
  }
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  int maxA = 1, flag1 = 0, flag2 = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i], res[i][0] = res[i][1] = 1, maxA = max(maxA, a[i]);
    d(i, a[i]);
    if (res[i][0] * res[i][1] == 1) {
      flag1 = 1;
    } else if (has[res[i][0] * res[i][1]]) {
      flag2 = 1;
    }
    has[res[i][0] * res[i][1]] = 1;
    g[res[i][0]].emplace_back(res[i][1]);
    g[res[i][1]].emplace_back(res[i][0]);
  }
  if (flag1) cout << 1, exit(0);
  if (flag2) cout << 2, exit(0);
  int ans = n + 1;
  for (int i = sqrt(maxA) + 1; i >= 1; --i) {
    ans = min(ans, bfs(i));
  }
  if (ans == n + 1)
    cout << -1;
  else
    cout << ans;
}