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>
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
using namespace std;
const long long N = 1e6 + 5;
const long long mod = 998244353;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
long long test = 1, n, a[N], spf[N], ct[N], par[N];
vector<long long> adj[N];
void sieve() {
  memset(spf, -1, sizeof(spf));
  for (long long i = 2; i * i < N; i++) {
    if (spf[i] == -1) {
      for (int j = 2 * i; j < N; j += i) {
        if (spf[j] == -1) spf[j] = i;
      }
    }
  }
}
long long normalize(long long n) {
  for (int i = 2; i * i <= n; i++) {
    long long x = i * i;
    while (n % x == 0) n /= x;
  }
  return n;
}
long long bfs(long long st) {
  memset(ct, 0, sizeof(ct));
  memset(par, 0, sizeof(par));
  queue<long long> q;
  q.push(st);
  ct[st] = 1;
  while (q.size()) {
    long long x = q.front();
    q.pop();
    for (auto it : adj[x]) {
      if (it == par[x]) continue;
      if (ct[it] != 0) {
        return ct[x] + ct[it] - 1;
      }
      ct[it] = ct[x] + 1;
      par[it] = x;
      q.push(it);
    }
  }
  return INF;
}
void solve() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i] = normalize(a[i]);
  }
  sort(a, a + n);
  if (a[0] == 1) {
    cout << 1 << "\n";
    return;
  }
  a[n] = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == a[i + 1]) {
      cout << 2 << "\n";
      return;
    }
    if (spf[a[i]] == -1) {
      adj[1].push_back(a[i]);
      adj[a[i]].push_back(1);
    } else {
      long long x = spf[a[i]], y = a[i] / x;
      adj[x].push_back(y);
      adj[y].push_back(x);
    }
  }
  long long ans = INF;
  for (int i = 2; i * i <= N; i++) {
    if (spf[i] == -1) {
      ans = min(ans, bfs(i));
    }
  }
  if (ans == INF) ans = -1;
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed;
  cout << setprecision(10);
  ;
  sieve();
  for (int i = 1; i <= test; i++) {
    solve();
  }
}