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;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long ppow(long long a, long long b, long long mod) {
  a %= mod;
  long long ans = 1 % mod;
  while (b) {
    if (b & 1) ans = (long long)ans * a % mod;
    a = (long long)a * a % mod;
    b >>= 1;
  }
  return ans;
}
long long readdd() {
  long long x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-') f = -1, c = getchar();
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  return f * x;
}
void printtt(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) printtt(x / 10);
  putchar(x % 10 + '0');
}
bool addd(long long a, long long b) { return a > b; };
const long long maxm = 1e6 + 5;
long long head[maxm], nt[maxm << 1], to[maxm << 1], w[maxm << 1], cnt, idx;
long long d[maxm], mark[maxm];
long long ans = 1e9;
long long n;
void add(long long x, long long y, long long z) {
  cnt++;
  nt[cnt] = head[x];
  head[x] = cnt;
  to[cnt] = y, w[cnt] = z;
}
bool isprime(long long x) {
  for (long long i = 2; i * i <= x; i++) {
    if (x % i == 0) return 0;
  }
  return 1;
}
void bfs(long long st) {
  queue<long long> q;
  q.push(st);
  memset(d, -1, sizeof d);
  for (long long i = 1; i <= idx; i++) mark[i] = 0;
  d[st] = 0;
  while (!q.empty()) {
    long long x = q.front();
    q.pop();
    for (long long i = head[x]; i; i = nt[i]) {
      if (mark[w[i]]) continue;
      mark[w[i]] = 1;
      long long v = to[i];
      if (d[v] == -1) {
        d[v] = d[x] + 1;
        q.push(v);
      } else {
        ans = min(ans, d[v] + d[x] + 1);
      }
    }
  }
}
signed main() {
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) {
    long long x;
    scanf("%lld", &x);
    long long a = 0, b = 1;
    for (long long j = 2; j * j <= x; j++) {
      if (x % j == 0) {
        long long cnt = 0;
        while (x % j == 0) {
          cnt++;
          x /= j;
        }
        if (cnt % 2) {
          if (!a)
            a = j;
          else
            b = j;
        }
      }
    }
    if (x != 1) {
      if (!a)
        a = x;
      else
        b = x;
    }
    if (!a) {
      puts("1");
      return 0;
    }
    add(a, b, idx);
    add(b, a, idx);
    idx++;
  }
  for (long long i = 1; i <= 1000; i++) {
    if (isprime(i)) {
      bfs(i);
    }
  }
  if (ans == 1e9) ans = -1;
  printf("%lld\n", ans);
  return 0;
}