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 MAXN = 1e6 + 5;
const int root = 1e3 + 10;
const int MAXN2 = 1e5 + 5;
struct edge {
  int u;
  int v;
  int ind;
  edge() {}
  edge(int u, int v, int ind) : u(u), v(v), ind(ind) {}
};
vector<int> D[MAXN];
vector<int> graph[MAXN];
bool simple[MAXN];
int dist[MAXN];
int pr[MAXN];
bool good[MAXN2];
vector<edge> pool;
void precalc() {
  for (int i = 0; i < MAXN; i++) simple[i] = 1;
  simple[0] = 0;
  simple[1] = 0;
  for (int i = 2; i < MAXN; i++) {
    if (!simple[i]) continue;
    for (int j = i; j < MAXN; j += i) {
      D[j].push_back(i);
      simple[j] = 0;
    }
    simple[i] = 1;
  }
}
pair<int, int> get(int val) {
  vector<int> all;
  for (int p : D[val]) {
    int coun = 1;
    long long now = p;
    while (val % now == 0) {
      now *= p;
      coun++;
    }
    coun--;
    if (coun % 2 == 1) {
      all.push_back(p);
    }
  }
  if (all.size() == 0) return {1, 1};
  if (all.size() == 1) return {all[0], 1};
  return {all[0], all[1]};
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int n;
  cin >> n;
  vector<long long> a(n);
  vector<int> all;
  set<int> all1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    auto res = get(a[i]);
    if (res.first == 1 && res.second == 1) {
      cout << 1 << endl;
      return 0;
    }
    all1.insert(res.first);
    int sz = pool.size();
    pool.push_back({res.first, res.second, i});
    graph[res.first].push_back(sz);
    all1.insert(res.second);
    pool.push_back({res.second, res.first, i});
    graph[res.second].push_back(sz + 1);
  }
  for (auto elem : all1) all.push_back(elem);
  int ans = n + 5;
  for (int go = 0; go < root; go++) {
    if (graph[go].size() == 0) continue;
    for (int i = 0; i < MAXN2; i++) good[i] = 0;
    for (int v : all) {
      dist[v] = -1;
      pr[v] = -1;
    }
    dist[go] = 0;
    deque<int> st;
    st.push_back(go);
    while (st.size() > 0) {
      int u = st[0];
      st.pop_front();
      for (int ind : graph[u]) {
        int v = pool[ind].v;
        if (dist[v] != -1) continue;
        dist[v] = dist[u] + 1;
        pr[v] = pool[ind].ind;
        good[pool[ind].ind] = 1;
        st.push_back(v);
      }
    }
    int len1 = n + 5;
    for (auto elem : pool) {
      if (good[elem.ind]) continue;
      int u = elem.u;
      int v = elem.v;
      if (dist[u] == -1 || dist[v] == -1) continue;
      len1 = min(len1, dist[u] + dist[v] + 1);
    }
    ans = min(ans, len1);
  }
  if (ans > n) {
    cout << -1 << endl;
  } else
    cout << ans << endl;
}