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;
const long long MXN = 100005;
const long long MXP = 1000005;
bool isprime[MXP];
vector<long long> primes;
void setup_primes() {
  memset(isprime, 1, sizeof isprime);
  primes.push_back(1);
  for (long long i = 2; i < MXP; i++) {
    if (isprime[i]) {
      primes.push_back(i);
      for (long long j = i * 2; j < MXP; j += i) {
        isprime[j] = false;
      }
    }
  }
}
long long n;
long long arr[MXN];
vector<long long> no(long long x) {
  vector<long long> ans;
  for (long long i = 2; i * i <= x + 2; i++) {
    if (x % i == 0) {
      long long f = 0;
      while (x % i == 0) {
        f++;
        x /= i;
      }
      if (f % 2 == 1) ans.push_back(i);
    }
  }
  if (x > 1) ans.push_back(x);
  return ans;
}
void answer(long long x) {
  cout << x << endl;
  exit(0);
}
vector<pair<long long, long long> > ed;
vector<pair<long long, long long> > adj[MXP];
long long dist[MXP];
long long scy(long long src) {
  long long best = INT_MAX;
  for (long long i = 0; i < primes.size(); i++) dist[primes[i]] = INT_MAX;
  queue<pair<long long, pair<long long, long long> > > proc;
  proc.push(make_pair(0, make_pair(src, -1)));
  vector<long long> r;
  while (!proc.empty()) {
    long long di = proc.front().first;
    long long no = proc.front().second.first;
    long long fr = proc.front().second.second;
    proc.pop();
    if (dist[no] < di) continue;
    dist[no] = di;
    long long od = di + 1;
    for (long long i = 0; i < adj[no].size(); i++) {
      long long ot = adj[no][i].first;
      long long f = adj[no][i].second;
      if (f == fr) continue;
      if (dist[ot] > od) {
        dist[ot] = od;
        proc.push(make_pair(od, make_pair(ot, f)));
      } else {
        if (ot == src) {
          r.push_back(f);
        } else {
          best = min(best, od + dist[ot]);
        }
      }
    }
  }
  for (long long i = 0; i < r.size(); i++) {
    long long a = ed[r[i]].first, b = ed[r[i]].second;
    if (a == src) {
      best = min(best, dist[b] + 1);
    } else if (b == src) {
      best = min(best, dist[a] + 1);
    }
  }
  return best;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  setup_primes();
  cin >> n;
  long long T = 0;
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
    vector<long long> r = no(arr[i]);
    if (r.empty()) {
      answer(1);
    } else if (r.size() == 1) {
      long long a = r[0], b = 1;
      adj[a].push_back(make_pair(b, T));
      adj[b].push_back(make_pair(a, T));
      ed.push_back(make_pair(a, b));
      T++;
    } else {
      long long a = r[0], b = r[1];
      adj[a].push_back(make_pair(b, T));
      adj[b].push_back(make_pair(a, T));
      ed.push_back(make_pair(a, b));
      T++;
    }
  }
  long long best = INT_MAX;
  for (long long src = 0; src < primes.size(); src++) {
    if (primes[src] <= 1002) best = min(best, scy(primes[src]));
  }
  if (best == INT_MAX) answer(-1);
  answer(best);
}