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;
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(long long &x, long long y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(long long &x, long long y) { return (y > x) ? x = y, 1 : 0; }
const int N = 1000000 + 1;
const int inf = (int)1e9 + 1;
const long long big = (long long)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const long double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;
int lp[N];
vector<int> pr;
void init() {
  fill(lp, lp + N, 0);
  for (int x = (2); x < (N); x++) {
    if (lp[x] == 0) {
      lp[x] = x;
      pr.push_back(x);
    }
    for (int i = 0; i < (int)pr.size() && pr[i] <= lp[x] && x * pr[i] < N;
         i++) {
      lp[x * pr[i]] = pr[i];
    }
  }
}
vector<pair<int, int> > g[N];
int cntEnd[N];
int ans = inf;
int dist[N];
int ttt = 0;
int used[N];
int go[N];
void bfs1(int s) {
  ttt++;
  used[s] = ttt;
  dist[s] = 0;
  go[s] = -1;
  queue<int> q;
  q.push(s);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto &v : g[u]) {
      if (used[v.first] != ttt) {
        dist[v.first] = dist[u] + 1;
        used[v.first] = ttt;
        go[v.first] = v.second;
        q.push(v.first);
      } else if (v.second != go[u]) {
        setmin(ans, dist[v.first] + dist[u] + 1);
      }
    }
  }
}
int d[N];
int col[N];
void bfs() {
  fill(d, d + N, inf);
  queue<int> q;
  for (int i = (0); i < (N); i++) {
    if (cntEnd[i] > 0) {
      d[i] = 0;
      col[i] = i;
      q.push(i);
    }
  }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto v : g[u]) {
      if (d[v.first] == inf) {
        d[v.first] = d[u] + 1;
        col[v.first] = col[u];
        q.push(v.first);
      } else if (col[v.first] != col[u]) {
        setmin(ans, 2 + d[u] + 1 + d[v.first]);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(20);
  cout << fixed;
  init();
  int n;
  cin >> n;
  for (int i = (0); i < (n); i++) {
    int x;
    cin >> x;
    vector<int> d;
    while (x > 1) {
      if ((int)d.size() == 0 || d.back() != lp[x]) {
        d.push_back(lp[x]);
      } else {
        d.pop_back();
      }
      x /= lp[x];
    }
    if ((int)d.size() == 0) {
      setmin(ans, 1);
    } else if ((int)d.size() == 1) {
      int u = d[0];
      if (cntEnd[u] > 0) {
        setmin(ans, 2);
      }
      cntEnd[u]++;
    } else if ((int)d.size() == 2) {
      int u = d[0], v = d[1];
      g[u].push_back({v, i});
      g[v].push_back({u, i});
    } else {
      assert(false);
    }
  }
  for (int i = (1); i < (1000 + 1); i++) {
    bfs1(i);
  }
  bfs();
  cout << (ans < inf ? ans : -1) << "\n";
  return 0;
}