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 inf = 2000000000;
const int N = 1e6 + 5;
const int M = 78520;
int black[M], dist[M], parent[M], primes[M];
vector<int> g[M];
bool prime[N];
int getPrimeNum[N];
int ans = inf;
void GenPrime() {
  memset(prime, true, sizeof(prime));
  prime[1] = false;
  for (int i = 2; i * i < N; i++) {
    if (prime[i]) {
      for (int j = i; j < N / i; j++) {
        prime[i * j] = false;
      }
    }
  }
  int PrimeCounter = 0;
  for (int i = 1; i < N; i++) {
    if (prime[i]) {
      primes[PrimeCounter] = i;
      getPrimeNum[i] = PrimeCounter++;
    }
  }
}
vector<int> fact(int first) {
  int i = 2;
  vector<int> result;
  while (i * i <= first) {
    if (first % i == 0) {
      int cnt = 0;
      while (first % i == 0) {
        first /= i;
        ++cnt;
      }
      if (cnt & 1) {
        result.push_back(getPrimeNum[i]);
      }
    }
    ++i;
  }
  if (first > 1) {
    result.push_back(getPrimeNum[first]);
  }
  return result;
}
int cycle(int v) {
  for (int i = 0; i < M; i++) {
    dist[i] = inf;
    parent[i] = -1;
  }
  dist[v] = 0;
  queue<int> q;
  q.push(v);
  int res = inf;
  while (!q.empty()) {
    int cur = q.front();
    if (dist[cur] + 1 >= ans) {
      break;
    }
    for (auto &to : g[cur]) {
      if (dist[to] == inf) {
        dist[to] = dist[cur] + 1;
        parent[to] = cur;
        q.push(to);
      } else if (parent[cur] != to) {
        res = min(res, dist[to] + dist[cur] + 1);
      }
    }
    q.pop();
  }
  return res;
}
int path() {
  queue<int> q;
  for (int i = 0; i < M; i++) {
    dist[i] = inf;
    if (black[i]) {
      q.push(i);
      dist[i] = 1;
      parent[i] = i;
    }
  }
  int res = inf;
  while (!q.empty()) {
    int cur = q.front();
    for (auto &to : g[cur]) {
      if (dist[to] > dist[cur] + 1) {
        dist[to] = dist[cur] + 1;
        parent[to] = parent[cur];
        q.push(to);
      } else if (parent[to] != parent[cur]) {
        res = min(res, dist[cur] + dist[to] + 1);
      }
    }
    q.pop();
  }
  return res;
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  GenPrime();
  int n;
  cin >> n;
  vector<vector<int>> a(n);
  set<pair<int, int>> s;
  for (int i = 0; i < n; i++) {
    int first;
    cin >> first;
    vector<int> res = fact(first);
    if (res.size() == 0) {
      cout << "1\n";
      return 0;
    }
    a[i] = res;
    if (a[i].size() == 1) {
      if (black[a[i][0]]) {
        ans = 2;
      }
      black[a[i][0]] = true;
    } else {
      if (a[i][0] > a[i][1]) {
        swap(a[i][0], a[i][1]);
      }
      g[a[i][0]].push_back(a[i][1]);
      g[a[i][1]].push_back(a[i][0]);
      if (ans == inf) {
        if (s.count({a[i][0], a[i][1]})) {
          ans = 2;
        }
        s.insert({a[i][0], a[i][1]});
      }
    }
  }
  if (ans == 2) {
    cout << ans << "\n";
    return 0;
  }
  ans = path();
  for (int i = 2; i < M; i++) {
    if (prime[i]) {
      int v = getPrimeNum[i];
      if (!black[v] && g[v].size() > 1) {
        ans = min(ans, cycle(v));
      }
    }
  }
  if (ans == inf) {
    ans = -1;
  }
  cout << ans;
}