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 + 111, K = 20;
const int mod = 1e9 + 7;
int ex[N], alone[N];
int spf[N];
vector<int> graph[N];
int arr[N], vis[N], cost[N], par[N], timer = 0;
int ans = 1e9;
void sieve() {
  for (int i = 0; i < N; i++) spf[i] = i;
  for (int i = 2; i * i < N; i++)
    if (spf[i] == i)
      for (int j = i * i; j < N; j += i) spf[j] = i;
}
void query(int u) {
  map<int, int> ff;
  while (u != 1) {
    ff[spf[u]]++;
    u /= spf[u];
  }
  vector<int> a;
  for (auto it : ff)
    if (it.second % 2) a.push_back(it.first);
  if (a.size() == 0)
    ans = 1;
  else if (a.size() == 1) {
    if (++ex[a[0]] == 2) ans = min(ans, 2);
    alone[a[0]] = 1;
  } else {
    if (++ex[a[0] * a[1]] == 2) ans = min(ans, 2);
    graph[a[0]].push_back(a[1]);
    graph[a[1]].push_back(a[0]);
  }
}
void bfs(int s) {
  pair<int, int> mns = make_pair(1e9, 1e9);
  timer++;
  queue<int> q;
  q.push(s);
  vis[s] = timer;
  cost[s] = 0;
  par[s] = -1;
  while (q.size()) {
    int u = q.front();
    q.pop();
    if (alone[u]) {
      if (cost[u] + 1 < mns.first)
        mns.second = mns.first, mns.first = cost[u] + 1;
      else if (cost[u] + 1 < mns.second)
        mns.second = cost[u] + 1;
    }
    for (auto v : graph[u]) {
      if (vis[v] == timer) {
        if (par[u] != v) {
          ans = min(ans, cost[u] + cost[v] + 1);
        }
      } else {
        cost[v] = cost[u] + 1;
        q.push(v);
        vis[v] = timer;
        par[v] = u;
      }
    }
  }
  if (mns.second != 1e9) ans = min(ans, mns.first + mns.second);
}
int main() {
  int n;
  cin >> n;
  sieve();
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
    query(arr[i]);
  }
  for (int i = 0; i * i < N; i++) {
    if (graph[i].size()) bfs(i);
  }
  if (ans == 1e9)
    cout << -1;
  else
    cout << ans;
}