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("Ofast")
const int mod = 1000000007;
const int inf = 1000000009;
const long long INF = 1000000000000000009;
const long long big = 1000000000000000;
const long double eps = 0.000000000000000000001;
using namespace std;
int tab[1000005], D[1000005], S[1000005];
vector<int> P[1000005];
bool T[1000005], O[1000005];
map<pair<int, int>, int> M;
void sito(int n) {
  for (int i = 2; i * i <= n; i++)
    if (!tab[i])
      for (int j = i * i; j <= n; j += i) tab[j] = i;
}
int wynik = inf;
vector<int> L;
void bfs(int n) {
  for (auto v : L) O[v] = 0, D[v] = inf, S[v] = 0;
  D[n] = 0;
  O[n] = 1;
  queue<int> Q;
  Q.push(n);
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (auto v : P[u]) {
      if (!O[v]) {
        D[v] = D[u] + 1;
        O[v] = 1;
        S[v] = u;
        Q.push(v);
      } else if (S[u] != v) {
        wynik = min(wynik, D[u] + D[v] + 1);
      }
    }
  }
}
bool kwadrat(int x) {
  int y = sqrt(x);
  for (int i = y - 10; i <= y + 10; i++)
    if (i * i == x) return 1;
  return 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  sito(1000001);
  for (int i = 1; i <= 1000001; i++)
    if (!tab[i]) tab[i] = i;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    if (kwadrat(a)) {
      cout << 1;
      return 0;
    }
    int x = tab[a];
    if ((a / x) % x == 0) {
      a /= x;
      a /= x;
      x = tab[a];
    }
    if ((a / x) % x == 0) {
      a /= x;
      a /= x;
      x = tab[a];
    }
    int y = a / x;
    if (tab[y] != y) {
      int z = tab[y];
      y /= z;
      y /= z;
    }
    if (!T[x]) L.push_back(x), T[x] = 1;
    if (!T[y]) L.push_back(y), T[y] = 1;
    P[x].push_back(y);
    P[y].push_back(x);
    if (M[make_pair(x, y)]) wynik = 2;
    M[make_pair(x, y)] = 1;
    M[make_pair(y, x)] = 1;
  }
  for (int i = 1; i <= 1000; i++) {
    if (tab[i] == i && T[i]) bfs(i);
  }
  if (wynik == inf)
    cout << -1;
  else
    cout << wynik;
  return 0;
}