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;
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (T i : v) os << i << ", ";
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const set<T> &v) {
  for (T i : v) os << i << " ";
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const multiset<T> &v) {
  for (T i : v) os << i << " ";
  return os;
}
template <class T, class second>
ostream &operator<<(ostream &os, const pair<T, second> &v) {
  os << v.first << ' ' << v.second;
  return os;
}
template <class T, class second>
ostream &operator<<(ostream &os, const map<T, second> &v) {
  for (auto i : v) os << '(' << i.first << " => " << i.second << ')' << ' ';
  return os;
}
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
const int N = 1e6 + 5;
vector<int> spf(N, 1);
vector<vector<int>> g(N);
vector<int> v(N);
vector<bool> vis(N, 0);
int n;
void f() {
  for (int i = 2; i < N; i++) spf[i] = i;
  for (int i = 2; i < N; i += 2) spf[i] = 2;
  for (int i = 3; i * i < N; i++)
    if (spf[i] == i)
      for (int j = i * i; j < N; j += i)
        if (spf[j] == j) spf[j] = i;
}
int ans = INT_MAX;
void bfs(int start) {
  vector<int> dist(N, (int)(1e9));
  vector<int> par(N, -1);
  dist[start] = 0;
  queue<int> q;
  q.push(start);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int child : g[x]) {
      if (dist[child] > dist[x] + 1) {
        dist[child] = 1 + dist[x];
        par[child] = x;
        q.push(child);
      } else if (par[x] != child && par[child] != x)
        ans = min(ans, dist[x] + dist[child] + 1);
    }
  }
}
void solve() {
  f();
  set<int> ss;
  for (int i = 1; i <= n; i++) {
    int temp = v[i];
    set<int> s;
    while (temp > 1) {
      if (s.count(spf[temp]))
        s.erase(spf[temp]);
      else
        s.insert(spf[temp]);
      temp /= spf[temp];
    }
    int num = 1;
    for (int i : s) num *= i;
    if (s.size() == 0 || num == 1) {
      ans = min(ans, 1);
    } else if (ss.count(num)) {
      ans = min(ans, 2);
    } else if (s.size() == 1) {
      g[1].push_back(*s.begin());
      g[*s.begin()].push_back(1);
    } else {
      g[*s.begin()].push_back(*s.rbegin());
      g[*s.rbegin()].push_back(*s.begin());
    }
    ss.insert(num);
    ss.insert(v[i]);
  }
  int sq = sqrt(N) + 50;
  for (int i = 1; i < sq; i++)
    if (!g[i].empty()) bfs(i);
  if (ans > n)
    cout << -1 << "\n";
  else
    cout << ans << "\n";
}
int main() {
  fast();
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> v[i];
  solve();
}