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 = 1000005;
vector<int> adj[N];
bool visted[N];
int level[N];
int parent[N];
int bfs(int start) {
  int ans = INT_MAX;
  queue<int> q;
  q.push(start);
  level[start] = 0;
  parent[start] = -1;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (auto i : adj[x]) {
      if (visted[i] == false) {
        q.push(i);
        visted[i] = true;
        level[i] = level[x] + 1;
        parent[i] = x;
      } else if (parent[i] != x and parent[x] != i) {
        ans = min(ans, level[x] + level[i] + 1);
      }
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed;
  cout.precision(10);
  int n;
  cin >> n;
  int a[n];
  map<int, int> m, mp;
  bool can = false;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int temp = a[i];
    m[a[i]]++;
    int x = sqrt(temp);
    if (x * x == temp) {
      cout << 1;
      return 0;
    }
    if (m[a[i]] > 1) can = true;
    int cnt = 0;
    for (int j = 2; j <= sqrt(temp); j++) {
      cnt = 0;
      if (temp % j == 0) {
        while (temp % j == 0) temp /= j, cnt++;
        if (cnt & 1) v.push_back(j);
      }
    }
    if (temp > 1) v.push_back(temp);
    if (v.size() < 2) {
      v.push_back(1);
      mp[v[0]]++;
      if (mp[v[0]] > 1) can = true;
    }
    adj[v[0]].push_back(v[1]);
    adj[v[1]].push_back(v[0]);
    v.clear();
  }
  if (can) {
    cout << 2;
    return 0;
  }
  int ans = INT_MAX;
  for (int i = 1; i < 1000; i++) {
    memset(visted, 0, sizeof visted);
    memset(level, 0, sizeof level);
    memset(parent, 0, sizeof parent);
    ans = min(ans, bfs(i));
  }
  if (ans == INT_MAX) ans = -1;
  cout << ans;
  return 0;
}