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;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
const int N = 1e6 + 5;
vector<pii> e[N];
vector<pii> factor(int x) {
  int up = sqrt(x), c;
  vector<pii> res;
  for (int i = 2; i <= up; ++i) {
    if (x % i == 0) {
      c = 0;
      while (x % i == 0) {
        x /= i, c++;
      };
      res.push_back({i, c});
    }
  }
  if (x != 1) res.push_back({x, 1});
  return res;
}
set<int> s;
int cnt[N], vis[N], dis[N];
int q[N];
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    auto d = factor(x);
    vi pr;
    for (auto p : d) {
      if (p.second % 2) pr.push_back(p.first), s.insert(p.first);
    }
    if (pr.empty()) {
      puts("1");
      return 0;
    } else if (pr.size() == 1) {
      cnt[pr[0]]++;
    } else {
      e[pr[0]].push_back({pr[1], i});
      e[pr[1]].push_back({pr[0], i});
    }
  }
  vi x((s).begin(), (s).end());
  int ans = n + 1;
  for (auto d : x) {
    if (cnt[d] >= 2) {
      puts("2");
      return 0;
    }
  }
  for (auto d : x)
    if (d <= 1000) {
      for (auto p : x) vis[p] = -1, dis[p] = n + 1;
      vis[d] = 1;
      dis[d] = 0;
      int t = 0;
      q[t++] = d;
      for (int i = 0; i < t; ++i) {
        int u = q[i];
        for (auto p : e[u]) {
          int v = p.first, w = p.second;
          if (vis[v] == -1) {
            vis[v] = w;
            dis[v] = dis[u] + 1;
            q[t++] = v;
          }
        }
      }
      int md1 = n + 1, md2 = n + 1;
      for (auto p : x)
        if (cnt[p]) {
          if (dis[p] < md1)
            md2 = md1, md1 = dis[p];
          else if (dis[p] < md2)
            md2 = dis[p];
        }
      ans = min(ans, md1 + md2 + 2);
      for (auto p : x)
        for (auto q : e[p]) {
          if (vis[p] != q.second && vis[q.first] != q.second) {
            ans = min(ans, dis[p] + dis[q.first] + 1);
          }
        }
    }
  if (ans == n + 1) {
    puts("-1");
  } else
    cout << ans << endl;
  return 0;
}