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 long long N = 1e6 + 7;
vector<long long> g[N];
set<pair<long long, long long> > ms;
long long e[N], ne[N], h[N], idx;
void add(long long a, long long b) {
  e[idx] = b;
  ne[idx] = h[a];
  h[a] = idx++;
}
void add_edge(long long u, long long v) {
  if (v < u) swap(u, v);
  if (ms.find({u, v}) != ms.end()) {
    cout << 2 << endl;
    exit(0);
  }
  ms.insert({u, v});
  add(u, v);
  add(v, u);
}
long long dist[N], son[N];
long long ans = 0x3f3f3f3f;
void bfs(long long S) {
  memset(dist, 0x3f, sizeof dist);
  queue<long long> q;
  q.push(S);
  dist[S] = 0;
  vector<long long> who;
  while (q.size()) {
    long long u = q.front();
    q.pop();
    who.push_back(u);
    for (long long i = h[u]; i != -1; i = ne[i]) {
      long long v = e[i];
      if (dist[u] + 1 < dist[v]) {
        dist[v] = dist[u] + 1;
        if (u == S)
          son[v] = v;
        else
          son[v] = son[u];
        q.push(v);
      } else if (u != S && v != S && son[u] != son[v])
        ans = min(ans, dist[u] + dist[v] + 1);
    }
  }
}
signed main() {
  memset(h, -1, sizeof h);
  long long n;
  cin >> n;
  vector<pair<long long, long long> > ed;
  while (n--) {
    long long x;
    cin >> x;
    vector<long long> a;
    for (long long i = 2; i * i <= x; ++i) {
      if (x % i == 0) {
        long long p = 0;
        while (x % i == 0) {
          ++p;
          x /= i;
        }
        if (p & 1) a.push_back(i);
      }
    }
    if (x > 1) a.push_back(x);
    if (a.empty()) {
      cout << 1 << endl;
      exit(0);
    } else if (a.size() == 1) {
      ed.push_back({1, a[0]});
    } else if (a.size() == 2) {
      ed.push_back({a[0], a[1]});
    }
  }
  for (auto e : ed) add_edge(e.first, e.second);
  for (long long u = 1; u <= 1007; ++u) bfs(u);
  if (ans >= 0x3f3f3f3f)
    cout << -1 << endl;
  else
    cout << ans << endl;
}