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 N = 1000000;
int arr[N + 100];
vector<int> vec;
int n, a[N + 100], gl[N + 100], ans = 1e9, byVal[N + 100], sk, byNum[N + 100];
vector<vector<int> > g(N + 100);
vector<int> d(N + 100);
vector<int> anc(N + 100);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  for (int i = 2; i <= N; i++) {
    if (arr[i] == 0) {
      for (int i1 = i; i1 <= N; i1 += i) {
        arr[i1] = i;
      }
    }
  }
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    int ch = a[i];
    set<int> divs;
    for (int x = ch; x > 1; x /= arr[x]) {
      if (divs.count(arr[x]) == 1) {
        divs.erase(arr[x]);
      } else {
        divs.insert(arr[x]);
      }
    }
    if (divs.size() == 0) {
      cout << 1;
      return 0;
    }
    if (divs.size() == 1) {
      divs.insert(1);
    }
    g[*(divs.begin())].push_back(*(++divs.begin()));
    g[*(++divs.begin())].push_back(*(divs.begin()));
  }
  for (int st = 1; st <= 1000; st++) {
    if (g[st].size() == 0) {
      continue;
    }
    d.assign(N + 5, -1);
    anc.assign(N + 5, -1);
    queue<int> q;
    q.push(st);
    anc[st] = -2;
    d[st] = 0;
    while (!q.empty()) {
      int ver = q.front();
      q.pop();
      for (auto to : g[ver]) {
        if (to == anc[ver]) {
          continue;
        }
        if (d[to] == -1) {
          d[to] = d[ver] + 1;
          anc[to] = ver;
          q.push(to);
        } else {
          ans = min(ans, d[to] + d[ver] + 1);
        }
      }
    }
  }
  cout << (ans == 1e9 ? -1 : ans);
}