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 int MAXN = 1e5 + 5;
struct edge {
  int to;
  int nex;
} e[MAXN * 2];
int head[MAXN * 2], tot;
void init() {
  memset(head, -1, sizeof(head));
  tot = 1;
}
void add(int a, int b) {
  e[tot] = edge{b, head[a]};
  head[a] = tot++;
  e[tot] = edge{a, head[b]};
  head[b] = tot++;
}
pair<int, int> jzk(int n) {
  vector<int> v;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      int cnt = 0;
      while (n % i == 0) {
        n /= i;
        cnt++;
      }
      if (cnt & 1) v.push_back(i);
    }
  }
  if (n > 1) v.push_back(n);
  if (v.size() == 0)
    return pair<int, int>{1, 1};
  else if (v.size() == 1)
    return pair<int, int>{1, v[0]};
  else
    return pair<int, int>{v[0], v[1]};
}
pair<int, int> a[MAXN];
long long t[MAXN * 2];
int book[MAXN * 2];
int vis[MAXN * 2];
int ans = MAXN;
int fa[MAXN * 2];
void bfs(int k) {
  memset(book, -1, sizeof(book));
  book[k] = 0;
  fa[k] = 0;
  queue<int> q;
  q.push(k);
  while (!q.empty()) {
    int t = q.front();
    q.pop();
    for (int i = head[t]; i + 1; i = e[i].nex) {
      int to = e[i].to;
      if (to == fa[t]) continue;
      if (book[to] != -1) {
        ans = min(ans, book[to] + book[t] + 1);
      } else {
        fa[to] = t;
        book[to] = book[t] + 1;
        q.push(to);
      }
    }
  }
}
int main() {
  init();
  int n;
  scanf("%d", &n);
  int num = 0;
  for (int i = 1; i <= n; i++) {
    int tt;
    scanf("%d", &tt);
    a[i] = jzk(tt);
    if (a[i] == pair<int, int>{1, 1}) {
      printf("1");
      return 0;
    }
    t[num++] = a[i].first;
    t[num++] = a[i].second;
  }
  sort(t, t + num);
  int qq = unique(t, t + num) - t;
  for (int i = 1; i <= n; i++) {
    a[i].first = lower_bound(t, t + qq, a[i].first) - t + 1;
    a[i].second = lower_bound(t, t + qq, a[i].second) - t + 1;
    add(a[i].first, a[i].second);
    if (a[i].first == 1) vis[a[i].second]++;
  }
  for (int i = 1; i <= qq; i++) {
    if (vis[a[i].second] >= 2) {
      printf("2");
      return 0;
    }
  }
  for (int i = 1; i <= qq; i++) {
    if (i > 1000) break;
    bfs(i);
  }
  if (ans == MAXN) ans = -1;
  printf("%d", ans);
}