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>
template <typename T>
void scan(T &x) {
  x = 0;
  bool _ = 0;
  T c = getchar();
  _ = c == 45;
  c = _ ? getchar() : c;
  while (c < 48 || c > 57) c = getchar();
  for (; c < 48 || c > 57; c = getchar())
    ;
  for (; c > 47 && c < 58; c = getchar()) x = (x << 3) + (x << 1) + (c & 15);
  x = _ ? -x : x;
}
template <typename T>
void printn(T n) {
  bool _ = 0;
  _ = n < 0;
  n = _ ? -n : n;
  char snum[65];
  int i = 0;
  do {
    snum[i++] = n % 10 + 48;
    n /= 10;
  } while (n);
  --i;
  if (_) putchar(45);
  while (i >= 0) putchar(snum[i--]);
}
template <typename First, typename... Ints>
void scan(First &arg, Ints &...rest) {
  scan(arg);
  scan(rest...);
}
template <typename T>
void print(T n) {
  printn(n);
  putchar(10);
}
template <typename First, typename... Ints>
void print(First arg, Ints... rest) {
  printn(arg);
  putchar(32);
  print(rest...);
}
using namespace std;
using pii = pair<int, int>;
const int MM = 1e6 + 2, lim = 1e3 + 1;
int n, ans = 1e9, dis[MM], x[MM], y[MM];
vector<pii> adj[MM];
vector<int> pre, pree, no;
queue<pii> q;
bool used[MM];
int main() {
  scan(n);
  for (int i = 0, v; i < n; i++) {
    map<int, int, greater<int>> mp;
    vector<int> a;
    scan(v);
    for (int j = 2; j * j <= v; j++) {
      while (v % j == 0) {
        mp[j]++;
        v /= j;
      }
    }
    mp[v]++;
    if (v != 1) mp[1]++;
    for (auto j : mp) {
      if (j.second & 1) a.push_back(j.first);
    }
    if (a.size() == 1) a.push_back(1);
    adj[a[0]].emplace_back(a[1], i);
    adj[a[1]].emplace_back(a[0], i);
    x[i] = a[0], y[i] = a[1];
  }
  memset(dis, 0x3f, sizeof dis);
  for (int i = 1; i < lim; i++) {
    if (adj[i].empty()) continue;
    dis[i] = 0;
    q.emplace(i, -1);
    while (q.size()) {
      int cur = q.front().first, pid = q.front().second;
      q.pop();
      pre.emplace_back(cur);
      for (auto e : adj[cur]) {
        int u = e.first, id = e.second;
        if (id == pid) continue;
        if (dis[cur] + 1 < dis[u]) {
          q.emplace(u, id);
          dis[u] = dis[cur] + 1;
          used[id] = 1;
          pree.emplace_back(id);
        } else {
          no.push_back(id);
        }
      }
    }
    for (int j : no) {
      if (!used[j]) {
        ans = min(ans, dis[x[j]] + dis[y[j]] + 1);
      }
    }
    no.clear();
    while (pre.size()) {
      dis[pre.back()] = 0x3f3f3f3f;
      pre.pop_back();
    }
    while (pree.size()) {
      used[pree.back()] = 0;
      pree.pop_back();
    }
  }
  print(ans == 1e9 ? -1 : ans);
  return 0;
}