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;
void fio() {}
void pti() {
  double timeuse = clock() * 1000.0 / CLOCKS_PER_SEC;
  cerr << "Timeuse " << timeuse << "ms" << endl;
}
void end() { exit(0); }
namespace io {
const int SIZ = 55;
int que[SIZ], op, qr;
char ch;
template <class I>
inline void gi(I& w) {
  ch = getchar(), op = 1, w = 0;
  while (!isdigit(ch)) {
    if (ch == '-') op = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    w = w * 10 + ch - '0';
    ch = getchar();
  }
  w *= op;
}
template <typename T, typename... Args>
inline void gi(T& t, Args&... args) {
  gi(t);
  gi(args...);
}
template <class I>
inline void print(I w) {
  qr = 0;
  if (!w) putchar('0');
  if (w < 0) putchar('-'), w = -w;
  while (w) que[++qr] = w % 10 + '0', w /= 10;
  while (qr) putchar(que[qr--]);
}
}  // namespace io
using io::gi;
using io::print;
const int N = 1e6 + 5;
int n, m, cnt = 1, num;
struct edge {
  int to, nxt;
};
edge e[N << 1];
int a[N], pri[N], head[N], dis[N];
bool isp[N], vis[N];
vector<int> t[N];
queue<pair<int, int>> q;
void add(int x, int y) {
  e[++cnt].to = y;
  e[cnt].nxt = head[x];
  head[x] = cnt;
}
void link(int x, int y) { add(x, y), add(y, x); }
void init() {
  m = N - 5;
  pri[0] = 1;
  for (int i = 2; i <= m; ++i) {
    if (!isp[i]) pri[++num] = i;
    for (int j = 1; j <= num && i * pri[j] <= m; ++j) {
      isp[i * pri[j]] = true;
      if (i % pri[j] == 0) break;
    }
  }
}
void div(int x) {
  int s = sqrt(x), lst = x;
  for (int i = 2; i <= s; ++i) {
    int res = 0;
    if (x % i == 0) {
      while (x % i == 0) x /= i, ++res;
      if (res & 1) t[lst].push_back(i);
    }
  }
  if (x > 1) t[lst].push_back(x);
}
int main() {
  fio();
  gi(n);
  init();
  for (int i = 1; i <= n; ++i) {
    gi(a[i]);
    if (!vis[a[i]]) div(a[i]);
    vis[a[i]] = true;
  }
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n; ++i) {
    int x = a[i];
    if (t[x].empty()) print(1), end();
    if (t[x].size() == 1) t[x].push_back(1);
    link(t[x][0], t[x][1]);
  }
  int ans = 0x3f3f3f3f;
  for (int k = 0; pri[k] * pri[k] <= m; ++k) {
    memset(dis, 0x3f3f3f3f, sizeof(dis));
    q.push({pri[k], 0});
    dis[pri[k]] = 0;
    while (!q.empty()) {
      int x = q.front().first, fa = q.front().second;
      q.pop();
      for (int i = head[x]; i; i = e[i].nxt) {
        if (i == fa || i == (fa ^ 1)) continue;
        int v = e[i].to;
        if (dis[v] == 0x3f3f3f3f)
          dis[v] = dis[x] + 1, q.push(make_pair(v, i));
        else
          ans = min(ans, dis[x] + dis[v] + 1);
      }
    }
  }
  if (ans == 0x3f3f3f3f)
    print(-1);
  else
    print(ans);
  end();
}