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 modPow(long long a, long long b) {
  long long res = 1;
  a %= 998244353;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % 998244353;
    a = a * a % 998244353;
  }
  return res;
}
long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
const int SIZE = 1000000;
const int N = 78499;
int spf[SIZE + 1];
vector<int> primes;
vector<int> factors;
vector<int> g[N + 1];
int rev[SIZE + 1];
void pre() {
  for (int i = 1; i < SIZE + 1; i++) spf[i] = SIZE;
  bool pr[SIZE + 1];
  for (int i = 1; i < SIZE + 1; i++) pr[i] = 0;
  for (int i = 2; i <= 1000; i++) {
    if (!pr[i]) {
      for (int j = 2 * i; j <= SIZE; j += i) {
        spf[j] = spf[j] < i ? spf[j] : i;
        pr[j] = 1;
      }
    }
  }
  for (int i = 2; i < SIZE + 1; i++)
    if (spf[i] == SIZE) spf[i] = i;
  for (int i = 1; i < SIZE + 1; i++)
    if (!pr[i]) primes.push_back(i);
  for (int i = 0; i < primes.size(); i++) {
    rev[primes[i]] = i + 1;
  }
}
int dp[N + 1];
map<pair<int, int>, int> mp;
int parent[N + 1];
int bfs(int st) {
  for (int i = 1; i < N + 1; i++) {
    dp[i] = (int)1e9;
    parent[i] = -1;
  }
  dp[st] = 0;
  queue<int> q;
  q.push(st);
  int ans = (int)1e9;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (auto &u : g[v]) {
      if (dp[v] + 1 < dp[u]) {
        dp[u] = dp[v] + 1;
        q.push(u);
        parent[u] = v;
      } else if (parent[v] != u && dp[v] + dp[u] > 1) {
        ans = ans < dp[v] + dp[u] + 1 ? ans : dp[v] + dp[u] + 1;
      }
    }
  }
  return ans;
}
void solve() {
  int n;
  cin >> n;
  pre();
  int ans = (int)1e9;
  for (int i = 1; i < n + 1; i++) {
    int a;
    cin >> a;
    factors.clear();
    while (a > 1) {
      int p = spf[a];
      int cc = 0;
      while (a % p == 0) {
        cc++;
        a /= p;
      }
      if (cc % 2 == 1) factors.push_back(p);
    }
    while (factors.size() < 2) factors.push_back(1);
    int u = factors[0], v = factors[1];
    if (u == 1 && v == 1) {
      ans = 1;
    }
    u = rev[u];
    v = rev[v];
    g[u].push_back(v);
    g[v].push_back(u);
    mp[make_pair(u, v)]++;
    mp[make_pair(v, u)]++;
  }
  if (ans != (int)1e9) {
    cout << ans << endl;
    return;
  }
  for (auto it = mp.begin(); it != mp.end(); it++) {
    if (it->second > 1) {
      ans = 2;
      break;
    }
  }
  if (ans != (int)1e9) {
    cout << ans << endl;
    return;
  }
  for (int i = 1; i < 171; i++) {
    ans = ans < bfs(i) ? ans : bfs(i);
  }
  if (ans == (int)1e9) ans = -1;
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int testCases = 1;
  while (testCases--) {
    solve();
  }
  return 0;
}