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;
const long long M = 1e9 + 7;
const long long inf = 1e18 + 5;
vector<int> g[N];
int prime[N];
void init() {
  iota(prime, prime + N, 0);
  prime[0] = 1;
  prime[1] = 0;
  for (int i = 2; i * i <= N; i++) {
    if (prime[i] == i) {
      for (int j = i * i; j < N; j += i) {
        if (prime[j] == j) prime[j] = i;
      }
    }
  }
}
void add_edge(int a, int b) {
  g[a].push_back(b);
  g[b].push_back(a);
}
int shortest_cycle(int node) {
  queue<int> q;
  q.push(node);
  int dis[N], par[N];
  for (int i = 0; i < N; i++) dis[i] = M, par[i] = 0;
  dis[node] = 0;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int it : g[x]) {
      if (dis[it] > dis[x] + 1) {
        dis[it] = dis[x] + 1;
        par[it] = x;
        q.push(it);
      } else if (it != par[x]) {
        int len = dis[it] + dis[x] + 1;
        return len;
      }
    }
  }
  return M;
}
int main() {
  init();
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    vector<int> v;
    while (x > 1) {
      int sf = prime[x];
      int ct = 0;
      while (x and x % sf == 0) {
        x /= sf;
        ct++;
      }
      if (ct & 1) v.push_back(sf);
    }
    if (v.empty()) {
      printf("%d\n", 1);
      exit(0);
    }
    v.push_back(1);
    add_edge(v[0], v[1]);
  }
  int ans = M;
  for (int i = 1; i * i < N; i++) ans = min(ans, shortest_cycle(i));
  if (ans == M) ans = -1;
  printf("%d\n", ans);
}