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;
template <class T>
inline void read(T &ret) {
  char c;
  int sgn;
  if (c = getchar(), c == EOF) return;
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  sgn = (c == '-') ? -1 : 1;
  ret = (c == '-') ? 0 : (c - '0');
  while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
  ret *= sgn;
  return;
}
inline void out(int x) {
  if (x > 9) out(x / 10);
  putchar(x % 10 + '0');
}
const int maxn = 1e6 + 10;
const int inf = 0x3f3f3f3f;
vector<int> edge[maxn];
int book[maxn], pre[maxn];
int ans = inf;
void bfs(int u) {
  memset(book, inf, sizeof(book));
  book[u] = 0;
  queue<int> q;
  q.push(u);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < edge[u].size(); i++) {
      int v = edge[u][i];
      if (v != pre[u]) {
        if (book[v] != inf)
          ans = min(ans, (book[u] + book[v] + 1));
        else
          pre[v] = u, book[v] = book[u] + 1, q.push(v);
        ;
      }
    }
  }
}
int main() {
  int n, x;
  read(n);
  for (int i = 0; i < n; i++) {
    read(x);
    for (int i = 2; i <= sqrt(x); i++) {
      while (x % (i * i) == 0) x /= i * i;
    }
    if (x == 1) {
      out(1);
      return 0;
    }
    int u = x, v = 1;
    edge[u].push_back(v);
    edge[v].push_back(u);
    for (int i = 2; i <= sqrt(x); i++) {
      if (x % i == 0) {
        u = x / i, v = i;
        edge[u].push_back(v);
        edge[v].push_back(u);
      }
    }
  }
  for (int i = 1; i <= sqrt(maxn); i++) bfs(i);
  if (ans != inf)
    out(ans);
  else
    printf("-1");
  return 0;
}