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 = 1e6 + 10;
const long long MOD = 1e9 + 7;
vector<int> g[N];
bool col[N];
int her[N], p[N];
set<int> s;
queue<int> q;
bool mp[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  bool bl = false;
  for (int i = 0; i < (n); ++i) {
    int tv;
    cin >> tv;
    vector<int> vc;
    for (int j = 2; j * j <= tv; j++) {
      if (tv % j == 0) {
        int qan = 0;
        while (tv % j == 0) {
          tv /= j;
          qan++;
        }
        if (qan % 2) vc.push_back(j);
      }
    }
    if (tv != 1) vc.push_back(tv);
    if (vc.size() == 0) {
      cout << 1 << endl;
      return 0;
    }
    if (vc.size() == 1) vc.push_back(1);
    int z = vc[0] * vc[1];
    if (mp[z]) bl = true;
    mp[z] = true;
    g[vc[0]].push_back(vc[1]);
    g[vc[1]].push_back(vc[0]);
    if (vc[0] <= 1000) s.insert(vc[0]);
    if (vc[1] <= 1000) s.insert(vc[1]);
  }
  if (bl) {
    cout << 2 << endl;
    return 0;
  }
  int ans = INT_MAX;
  for (auto tv : s) {
    q.push(tv);
    memset(her, 0, sizeof(her));
    memset(col, 0, sizeof(col));
    memset(p, 0, sizeof(p));
    col[tv] = true;
    her[tv] = 0;
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      for (auto to : g[v]) {
        if (col[to]) {
          if (to == p[v]) continue;
          ans = min(ans, her[to] + her[v] + 1);
          continue;
        }
        q.push(to);
        col[to] = true;
        her[to] = her[v] + 1;
        p[to] = v;
      }
    }
  }
  if (ans == INT_MAX)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}