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 int MAXN = 1e6 + 10;
int spf[MAXN], is[MAXN], vis[MAXN], ds[MAXN], pre[MAXN];
vector<int> g[MAXN];
int get(int st) {
  int ans = 1e9;
  queue<int> q;
  q.push(st);
  vis[st] = st;
  ds[st] = 0;
  while (int(q.size())) {
    int pos = q.front();
    q.pop();
    for (auto x : g[pos]) {
      if (vis[x] == st) {
        if (pre[pos] != x) ans = min(ans, ds[pos] + ds[x] + 1);
      } else {
        vis[x] = st;
        pre[x] = pos;
        ds[x] = ds[pos] + 1;
        q.push(x);
      }
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (int i = 2, ThxDem = MAXN; i < ThxDem; ++i)
    if (!spf[i])
      for (int j = i; j < MAXN; j += i)
        if (!spf[j]) spf[j] = i;
  int n;
  cin >> n;
  vector<long long> a(n);
  vector<vector<int>> ps(n);
  map<vector<int>, int> mp;
  for (int i = 0, ThxDem = n; i < ThxDem; ++i) {
    cin >> a[i];
    long long x = a[i];
    while (x > 1) {
      long long nw = spf[x], pw = 0;
      while (spf[x] == nw) pw++, x /= spf[x];
      if (pw & 1) ps[i].push_back(nw);
    }
    if (!int(ps[i].size())) cout << "1\n", exit(0);
    mp[ps[i]]++;
  }
  int can = 0;
  for (auto x : mp) {
    if (x.second >= 2) cout << "2\n", exit(0);
    if (int(x.first.size()) == 1)
      g[1].push_back(x.first[0]), g[x.first[0]].push_back(1);
    else
      g[x.first[1]].push_back(x.first[0]), g[x.first[0]].push_back(x.first[1]);
    can |= int(x.first.size()) > 1;
  }
  if (!can) cout << "-1\n", exit(0);
  int ans = 1e9, MX = 1001;
  for (int i = 1, ThxDem = MX; i < ThxDem; ++i) ans = min(ans, get(i));
  if (ans == 1e9) ans = -1;
  cout << ans << "\n";
}