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>
template <class T>
T Min(T _a, T _b) {
  return _a < _b ? _a : _b;
}
template <class T>
T Max(T _a, T _b) {
  return _a > _b ? _a : _b;
}
template <class T>
T chk_Min(T &_a, T _b) {
  return _a = (_a < _b ? _a : _b);
}
template <class T>
T chk_Max(T &_a, T _b) {
  return _a = (_a > _b ? _a : _b);
}
const int N = 1e6 + 1e4;
const int M = 1100;
const int INF = 0x3f3f3f3f;
int n, ans = INF;
int dis[N], fa[N];
bool marked[N], pool[N];
struct edge {
  int cur, to, next;
} e[N << 1];
int ehead[N], ecnt = 1;
inline void add_edge(int now, int to) {
  ecnt++;
  e[ecnt].cur = now;
  e[ecnt].to = to;
  e[ecnt].next = ehead[now];
  ehead[now] = ecnt;
}
int bfs(int st) {
  memset(dis, INF, sizeof(dis));
  memset(fa, 0, sizeof(fa));
  std::queue<int> q;
  q.push(st);
  dis[st] = 0;
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (int i = ehead[cur]; i; i = e[i].next) {
      if (e[i].to == fa[cur]) continue;
      if (dis[e[i].to] >= INF) {
        fa[e[i].to] = cur;
        dis[e[i].to] = dis[cur] + 1;
        q.push(e[i].to);
      } else {
        return dis[cur] + dis[e[i].to] + 1;
      }
    }
  }
  return INF;
}
int main() {
  scanf("%d", &n);
  for (int i = 1, x; i <= n; i++) {
    scanf("%d", &x);
    std::vector<int> a;
    int cnt = std::sqrt(x) + 1;
    while (cnt > 1) {
      int cnt_pow = cnt * cnt;
      while (x % cnt_pow == 0) x /= cnt_pow;
      cnt--;
    }
    if (x == 1) chk_Min(ans, 1);
    if (pool[x]) chk_Min(ans, 2);
    pool[x] = true;
    int tmp = std::sqrt(x);
    for (int j = 2; j <= tmp; j++) {
      if (x % j == 0) {
        a.push_back(j);
        a.push_back(x / j);
        break;
      }
    }
    if (a.size() == 0) {
      add_edge(1, x);
      add_edge(x, 1);
    } else if (a.size() != 0) {
      add_edge(a[0], a[1]);
      add_edge(a[1], a[0]);
    }
  }
  if (ans != INF) {
    printf("%d\n", ans);
    return 0;
  }
  for (int i = 1; i <= 1000; i++) {
    if (ehead[i]) chk_Min(ans, bfs(i));
  }
  if (ans >= INF) ans = -1;
  printf("%d\n", ans);
}