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 INT = long long;
int n;
int cnt[1000100];
int id[1000100];
vector<int> adj[1000100];
int dis[1000100];
int flag[1000100];
int runs = 0;
int solve(int u) {
  vector<int> vec;
  queue<int> q;
  q.push(u);
  runs++;
  flag[u] = runs;
  int ans = 0x3f3f3f3f;
  dis[u] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vec.push_back(u);
    for (int v : adj[u]) {
      if (flag[v] != runs) {
        dis[v] = dis[u] + 1;
        flag[v] = runs;
        q.push(v);
      }
    }
  }
  for (int u : vec) {
    int mn0 = 0x3f3f3f3f, mn1 = 0x3f3f3f3f;
    for (int v : adj[u])
      if (dis[v] <= dis[u]) {
        int x = dis[v];
        if (mn1 > x) swap(x, mn1);
        if (mn0 > x) swap(x, mn0);
      }
    if (mn0 != 0x3f3f3f3f) {
      ans = min(ans, mn0 + mn1 + 2);
    }
  }
  return ans;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int u;
    scanf("%d", &u);
    int p = 1;
    for (int j = 2; j * j <= u; j++)
      if (u % j == 0) {
        int ss = 0;
        while (u % j == 0) u /= j, ss++;
        if (ss & 1) p *= j;
      }
    if (u > 1) p *= u;
    cnt[p]++;
  }
  if (cnt[1]) return puts("1"), 0;
  for (int i = 1; i < 1000100; i++)
    if (cnt[i] > 1) {
      return puts("2"), 0;
    }
  for (int i = 1; i < 1000100; i++)
    if (cnt[i]) {
      int u = i;
      for (int j = 2; j * j <= u; j++)
        if (u % j == 0) {
          u /= j;
          adj[j].push_back(u);
          adj[u].push_back(j);
          break;
        }
      if (i == u) adj[1].push_back(u), adj[u].push_back(1);
    }
  int ans = n + 1;
  for (int i = 1; i * i < 1000100; i++)
    if (adj[i].size() > 1) {
      ans = min(ans, solve(i));
    }
  if (ans == n + 1)
    puts("-1");
  else
    cout << ans << endl;
  return 0;
}