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;
int const N = 1e6 + 10;
vector<int> plist[N];
vector<bool> np(N, 0);
vector<int> primes;
vector<int> g[N];
void sieve() {
  primes.push_back(1);
  for (int i = 2; i < N; i++) {
    if (np[i]) continue;
    primes.push_back(i);
    for (int j = i; j < N; j += i) {
      if (j != i) np[j] = 1;
      plist[j].push_back(i);
    }
  }
}
pair<int, int> create_prime_pair(int n) {
  vector<int> v;
  for (auto x : plist[n]) {
    int _n = n;
    int cnt = 0;
    while (_n % x == 0) cnt++, _n /= x;
    if (cnt & 1) v.push_back(x);
  }
  v.push_back(1);
  v.push_back(1);
  assert(v.size() <= 4);
  return {v[0], v[1]};
}
int n;
vector<int> undo;
int dist[N];
bool vis[N];
int bfs(int p) {
  undo.push_back(p);
  dist[p] = 0;
  queue<pair<int, int> > q;
  q.push({p, -1});
  while (!q.empty()) {
    int u = q.front().first;
    int pr = q.front().second;
    q.pop();
    for (auto x : g[u]) {
      if (x == pr) continue;
      if (vis[x]) return 1 + dist[u] + dist[x];
      q.push({x, u});
      vis[x] = 1;
      undo.push_back(x);
      dist[x] = 1 + dist[u];
    }
  }
  return n + 1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  sieve();
  cin >> n;
  vector<pair<int, int> > v(n);
  bool one = 0, two = 0;
  map<pair<int, int>, int> cnt;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    pair<int, int> p = create_prime_pair(tmp);
    cnt[p]++;
    v[i] = p;
    if (p == pair<int, int>(1, 1)) one = 1;
    if (cnt[p] == 2) two = 1;
  }
  if (one) {
    cout << "1\n";
    exit(0);
  }
  if (two) {
    cout << "2\n";
    exit(0);
  }
  for (int i = 0; i < n; i++) {
    g[v[i].first].push_back(v[i].second);
    g[v[i].second].push_back(v[i].first);
  }
  int ans = n + 1;
  for (int i = 0; i < primes.size(); i++) {
    if (primes[i] * 1LL * primes[i] > N) break;
    int tmp = bfs(primes[i]);
    ans = min(ans, tmp);
    for (auto x : undo) {
      vis[x] = 0;
      dist[x] = 0;
    }
    undo.clear();
  }
  if (ans > n) {
    cout << "-1" << endl;
  } else
    cout << ans << endl;
  return 0;
}