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>
#pragma GCC optimize(2)
using namespace std;
const long long mod = 1e9 + 7;
const long double eps = 1e-9;
const long double PI = acos(-1.0);
int n, t, ans = 0x3f3f3f3f, vis[1010000], deep[1010000];
vector<int> edge[1010000];
map<pair<int, int>, int> mp;
void cal(int x) {
  int u = 0, v = 0;
  for (int i = 2; i * i <= x; i++) {
    if (x % i != 0) continue;
    int con = 0;
    while (x % i == 0) {
      con++;
      x /= i;
      continue;
    }
    if (con & 1) (u ? v : u) = i;
  }
  if (x != 1) (u ? v : u) = x;
  if (!u) ans = 1;
  if (!v) v = u, u = 1;
  if (mp[make_pair(u, v)]) {
    ans = min(ans, 2);
    return;
  }
  edge[u].push_back(v), edge[v].push_back(u);
  mp[make_pair(u, v)] = 1, mp[make_pair(v, u)] = 1;
}
void bfs(int now) {
  queue<pair<int, int> > que;
  vis[now] = t, deep[now] = 0;
  que.push(make_pair(now, 0));
  while (!que.empty()) {
    auto temp = que.front();
    que.pop();
    for (auto to : edge[temp.first]) {
      if (to == temp.second) continue;
      if (vis[to] == t) {
        ans = min(ans, deep[temp.first] + deep[to] + 1);
        continue;
      }
      vis[to] = t, deep[to] = deep[temp.first] + 1;
      que.push(make_pair(to, temp.first));
    }
  }
}
int main() {
  cin >> n;
  for (int i = 1, x; i <= n; i++) {
    cin >> x;
    cal(x);
  }
  for (int i = 1; i <= 1000; i++) {
    ++t;
    bfs(i);
  }
  if (ans == 0x3f3f3f3f)
    cout << -1;
  else
    cout << ans;
  return 0;
}