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 w = 1e5 + 5;
const long long mod = 1e9 + 7;
vector<int> ve[w], ve2[w];
int a[w];
map<int, int> ma;
set<int> se;
set<pair<int, int> > ss;
int ans = 1e9;
int dis[w];
int main() {
  int i, j;
  int n;
  cin >> n;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    int x = a[i];
    for (j = 2; 1LL * j * j <= x; j++) {
      if (x % j == 0) {
        int u = 0;
        while (x % j == 0) u++, x /= j;
        u %= 2;
        if (u) ve[i].push_back(j);
      }
    }
    if (x > 1) ve[i].push_back(x);
    if (ve[i].size() == 0) {
      puts("1");
      return 0;
    }
  }
  int tot = 1;
  for (i = 1; i <= n; i++) {
    if (ve[i].size() == 1) {
      int x = 1, y = ve[i][0];
      if (!ma[x]) ma[x] = tot, tot++;
      if (!ma[y]) ma[y] = tot, tot++;
      if (se.count(y)) {
        puts("2");
        return 0;
      }
      se.insert(y);
      ve2[ma[x]].push_back(ma[y]);
      ve2[ma[y]].push_back(ma[x]);
    }
    if (ve[i].size() == 2) {
      int x = ve[i][0], y = ve[i][1];
      if (!ma[x]) ma[x] = tot, tot++;
      if (!ma[y]) ma[y] = tot, tot++;
      if (ss.count({x, y})) {
        puts("2");
        return 0;
      }
      ss.insert({x, y});
      ve2[ma[x]].push_back(ma[y]);
      ve2[ma[y]].push_back(ma[x]);
    }
  }
  queue<pair<int, int> > qu;
  for (i = 1; i <= 1000; i++) {
    if (ma[i]) {
      for (j = 1; j < tot; j++) dis[j] = 0;
      qu.push({ma[i], 0});
      dis[ma[i]] = 1;
      while (!qu.empty()) {
        int x = qu.front().first, fa = qu.front().second;
        qu.pop();
        for (j = 0; j < ve2[x].size(); j++) {
          int y = ve2[x][j];
          if (y == fa) continue;
          if (dis[y] == 0)
            dis[y] = dis[x] + 1, qu.push({y, x});
          else {
            ans = min(ans, dis[x] + dis[y] - 1);
          }
        }
      }
    }
  }
  if (ans == 1e9)
    puts("-1");
  else
    printf("%d\n", ans);
  return 0;
}