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;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int N, a[100001];
vector<int> divs[100001];
bool notPrime[1000001];
vector<int> primes;
map<int, int> mp;
vector<pair<int, int>> adj[100001];
int edgeCnt;
void sieve() {
  for (int i = 2; i * i <= 10000000; i++) {
    if (notPrime[i]) continue;
    for (int j = i + i; j <= 1000000; j += i) notPrime[j] = true;
  }
}
int ans = 2001001001;
int dis[1000001];
int vis[1000001];
void bfs(int source, int iter) {
  queue<pair<int, int>> q;
  dis[source] = 0;
  vis[source] = iter;
  q.push({source, -1});
  while (!q.empty()) {
    int x = q.front().first;
    int prevEdge = q.front().second;
    q.pop();
    for (auto y : adj[x]) {
      if (y.second == prevEdge) continue;
      if (vis[y.first] == iter) ans = min(ans, dis[x] + dis[y.first] + 1);
      if (vis[y.first] != iter) {
        vis[y.first] = iter;
        dis[y.first] = dis[x] + 1;
        q.push(y);
      }
    }
  }
}
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) cin >> a[i];
  sieve();
  for (int i = 1; i <= 1000000; i++) {
    if (!notPrime[i]) {
      mp[i] = primes.size();
      primes.push_back(i);
    }
  }
  for (int i = 0; i < N; i++) {
    vector<int> divs;
    for (int j = 2; j * j <= a[i]; j++) {
      int cnt = 0;
      while (a[i] % j == 0) {
        a[i] /= j;
        cnt++;
      }
      if (cnt % 2 == 1) {
        divs.push_back(j);
        a[i] *= j;
      }
    }
    if (a[i] > 1) {
      if (divs.size() == 0)
        divs.push_back(a[i]);
      else
        divs.push_back(a[i] / divs[0]);
    }
    if (a[i] == 1) {
      cout << 1 << endl;
      return 0;
    }
    if (divs.size() == 1) divs.push_back(1);
    adj[mp[divs[0]]].push_back({mp[divs[1]], edgeCnt});
    adj[mp[divs[1]]].push_back({mp[divs[0]], edgeCnt});
    edgeCnt++;
  }
  for (int i = 0; primes[i] * primes[i] < 1001000; i++) {
    bfs(i, i + 1);
  }
  if (ans == 2001001001)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}