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 rnd(chrono::high_resolution_clock::now().time_since_epoch().count() +
            'd' + 'o' + 'i' + 'n' + 'g' + 'g' + 'e' + 'y');
const long long maxc = 1e6 + 1;
const long long maxn = 1e5 + 1;
const long long inf = 1e9;
const long long sq = 1e3 + 1;
double start_time;
vector<long long> g[maxn];
vector<long long> co, a;
long long idx(long long x) {
  return lower_bound(co.begin(), co.end(), x) - co.begin();
}
signed main() {
  start_time = clock();
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  long long n;
  cin >> n;
  vector<pair<long long, long long>> e;
  for (long long i = 0; i < n; ++i) {
    long long x;
    cin >> x;
    vector<long long> v;
    for (long long t = 2; t * t <= x; ++t) {
      long long cnt = 0;
      while (x % t == 0) {
        x /= t;
        ++cnt;
      }
      if (cnt % 2) v.push_back(t);
    }
    if (x > 1) v.push_back(x);
    if (!(long long)v.size()) {
      cout << 1;
      return 0;
    }
    if ((long long)v.size() > 1) {
      e.push_back({v[0], v[1]});
    }
    x = 1;
    for (long long t : v) {
      co.push_back(t);
      x *= t;
    }
    a.push_back(x);
    co.push_back(x);
  }
  n = (long long)a.size();
  sort(co.begin(), co.end());
  co.erase(unique(co.begin(), co.end()), co.end());
  for (auto t : e) {
    long long a = idx(t.first), b = idx(t.second);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<long long> us((long long)co.size(), 0);
  for (long long x : a) {
    long long pos = idx(x);
    us[pos]++;
    if (us[pos] > 1) {
      cout << 2;
      return 0;
    }
  }
  long long ans = inf;
  for (long long i = 0; i < (long long)co.size() && co[i] <= sq; ++i) {
    long long p = i;
    vector<long long> d((long long)co.size(), inf),
        fr((long long)co.size(), -1);
    d[p] = 0;
    queue<long long> q;
    q.push(p);
    while ((long long)q.size()) {
      long long v = q.front();
      q.pop();
      for (long long u : g[v]) {
        if (u == fr[v]) continue;
        if (d[v] + 1 < d[u]) {
          fr[u] = v;
          d[u] = d[v] + 1;
          q.push(u);
        } else {
          ans = min(ans, d[v] + d[u] + 1);
        }
      }
    }
    long long ra = inf, rb = inf;
    for (long long i = 0; i < (long long)co.size(); ++i) {
      if (!us[i]) continue;
      if (d[i] < ra) {
        rb = ra;
        ra = d[i];
      } else
        rb = min(rb, d[i]);
    }
    ans = min(ans, ra + rb + 2);
  }
  if (ans >= inf)
    cout << -1;
  else
    cout << ans;
  return 0;
}