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;
vector<int> E[1000005];
vector<int> prime;
int sqr[1000005];
int n;
int A[100005];
int Map[1000005];
int Mark[1000005];
queue<int> q;
int p[1000005];
set<pair<int, int> > S;
int isprime(int n) {
  if (n == 2) return true;
  if (n % 2 == 0) return false;
  for (int i = 3; i * i <= n; i += 2) {
    if (n % i == 0) return false;
  }
  return true;
}
int bfs(int st) {
  q.push(st);
  Map[st] = 0;
  vector<int> V;
  int ans = 1e9;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    V.push_back(u);
    for (int v : E[u]) {
      if (v != p[u]) {
        if (Map[v] != -1) {
          ans = min(ans, Map[u] + Map[v] + 1);
        } else if (Map[v] == -1) {
          Map[v] = Map[u] + 1;
          p[v] = u;
          q.push(v);
        }
      }
    }
  }
  for (int v : V) {
    Map[v] = p[v] = -1;
  }
  return ans;
}
int bfs2(int st) {
  q.push(st);
  Map[st] = 0;
  vector<int> V;
  int ans = 1e9;
  vector<int> MVal;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    V.push_back(u);
    if (Mark[u] == 1 && u != st && Mark[st] == 1) {
      ans = min(ans, Map[u]);
    }
    if (Mark[u] == 1) {
      MVal.push_back(Map[u]);
    }
    for (int v : E[u]) {
      if (v != p[u]) {
        if (Map[v] == -1) {
          Map[v] = Map[u] + 1;
          p[v] = u;
          q.push(v);
        }
      }
    }
  }
  if (MVal.size() > 1) {
    int V1 = 1e9, V2 = 1e9;
    for (int i = 0; i < MVal.size(); i++) {
      int v = MVal[i];
      if (v < V1) {
        V2 = V1;
        V1 = v;
      } else {
        if (v < V2) {
          V2 = v;
        }
      }
    }
    ans = min(ans, V1 + V2);
  }
  for (int v : V) {
    Map[v] = p[v] = -1;
  }
  return ans;
}
int main() {
  for (int i = 2; i <= 1000; i++) {
    if (isprime(i)) prime.push_back(i);
  }
  for (int i = 1; i <= 1000; i++) sqr[i * i] = 1;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &A[i]);
    Map[A[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    if (sqr[A[i]]) {
      printf("1\n");
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (Map[A[i]] > 1) {
      printf("2\n");
      return 0;
    }
    Map[A[i]] = 0;
  }
  for (int i = 1; i <= n; i++) {
    int x = A[i];
    vector<int> V;
    for (int j = 0; j < prime.size(); j++) {
      if (x % prime[j] == 0) {
        int cnt = 0;
        while (x % prime[j] == 0) {
          x /= prime[j];
          cnt ^= 1;
        }
        if (cnt) V.push_back(prime[j]);
      }
    }
    if (x > 1) V.push_back(x);
    if (V.size() == 1) {
      Mark[V.back()]++;
      if (Mark[V.back()] > 1) {
        printf("2\n");
        return 0;
      }
    } else if (V.size() == 2) {
      if (V[0] > V[1]) swap(V[0], V[1]);
      if (S.find(make_pair(V[0], V[1])) != S.end()) {
        printf("2\n");
        return 0;
      }
      S.insert(make_pair(V[0], V[1]));
      E[V[0]].push_back(V[1]);
      E[V[1]].push_back(V[0]);
    } else {
      assert(1 == 2);
    }
  }
  for (int i = 1; i <= 1000000; i++) Map[i] = p[i] = -1;
  int ans = 1e9;
  for (int i = 2; i <= 1000; i++) {
    if (E[i].size() > 0) {
      ans = min(ans, bfs(i));
    }
    ans = min(ans, bfs2(i) + 2);
  }
  if (ans == 1e9) ans = -1;
  printf("%d\n", ans);
  return 0;
}