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 MOD = 30000 + 7;
const int N = 503;
const int A = 110;
const int K = 101;
const int inf = 1e9;
vector<vector<pair<long long, long long>>> tre;
vector<long long> factor(long long a) {
  vector<long long> ans;
  for (long long i = 2; a > 1; i++) {
    if (i * i > a) i = a;
    long long zz = 0;
    while (a % i == 0) {
      a /= i;
      zz++;
    }
    if (zz % 2) ans.push_back(i);
  }
  return move(ans);
}
long long ID = 0;
long long ans = INT_MAX;
const long long MAXA = 1e6 + 10;
bool used[MAXA];
long long rrast[MAXA];
void find_cycle(long long v) {
  memset(used, 0, sizeof(used));
  memset(rrast, -1, sizeof(rrast));
  deque<long long> q;
  q.push_back(v);
  rrast[v] = 0;
  while (!q.empty()) {
    long long curv = q.front();
    q.pop_front();
    for (auto i : tre[curv]) {
      if (used[i.second]) continue;
      if (rrast[i.first] != -1) {
        ans = min(ans, rrast[i.first] + 1 + rrast[curv]);
        return;
      } else {
        rrast[i.first] = rrast[curv] + 1;
        used[i.second] = true;
        q.push_back({i.first});
      }
    }
  }
}
int32_t main() {
  cin.sync_with_stdio(0);
  cout.sync_with_stdio(0);
  long long n;
  cin >> n;
  tre.resize(MAXA);
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    vector<long long> fct = factor(x);
    if (fct.size() == 2) {
      long long f = fct[0];
      long long s = fct[1];
      tre[f].push_back({s, ID});
      tre[s].push_back({f, ID});
      ID++;
    }
    if (fct.size() == 1) {
      tre[1].push_back({fct[0], ID});
      tre[fct[0]].push_back({1, ID});
      ID++;
    }
    if (fct.size() == 0) cout << 1, exit(0);
    ;
  }
  for (long long i = 1; i <= 1000; i++) {
    find_cycle(i);
  }
  cout << (ans != INT_MAX ? ans : -1);
  return 0;
}