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 JAVA):

Solution:
import java.io.*;
import java.util.*;

public class Solution {
    private static final int MAX_VALUE = 1000000;
    private static final int MAX_ROOT = 1000;

    public void solve() {
        List<Integer> prime = sieve(MAX_VALUE);

        HashMap<Integer, Integer> idx = new HashMap<>();
        int cnt = 0;

        int n = reader.nextInt();
        int[][] edges = new int[n][2];
        HashSet<Integer> root = new HashSet<>();

        for (int i = 0; i < n; i++) {
            int[] a = simplify(prime, reader.nextInt());

            int x = a[0], y = a[1];
            int s = x * y;

            if (s == 1) {
                writer.println(1);
                return;
            }

            if (!idx.containsKey(x)) idx.put(x, cnt++);
            if (!idx.containsKey(y)) idx.put(y, cnt++);

            int u = idx.get(x);
            int v = idx.get(y);

            edges[i][0] = u;
            edges[i][1] = v;

            if (x <= MAX_ROOT) root.add(u);
            if (y <= MAX_ROOT) root.add(v);
        }

        List<Integer>[] adj = new List[cnt];
        for (int i = 0; i < cnt; i++) adj[i] = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int u = edges[i][0];
            int v = edges[i][1];
            adj[u].add(v);
            adj[v].add(u);
        }

        writer.println(shortestCycle(adj, root));
    }

    private int shortestCycle(List<Integer>[] adj, HashSet<Integer> root) {
        int res = MAX_VALUE;

        int n = adj.length;
        int[] parent = new int[n];
        int[] level = new int[n];

        Deque<Integer> queue = new LinkedList<>();

        for (int start : root) {
            Arrays.fill(level, -1);

            parent[start] = start;
            level[start] = 0;
            queue.add(start);

            while (!queue.isEmpty()) {
                int u = queue.poll();
                if (level[u] + 1 >= res) continue;

                for (int v : adj[u]) {
                    if (level[v] == -1) {
                        parent[v] = u;
                        level[v] = level[u] + 1;
                        queue.add(v);
                        continue;
                    }

                    if (v == parent[u]) continue;
                    res = Math.min(res, level[u] + level[v] + 1);
                }
            }
        }

        return res < MAX_VALUE ? res : -1;
    }

    private int[] simplify(List<Integer> prime, int a) {
        for (int p : prime) {
            int q = p * p;
            if (q > a) break;
            while (a % q == 0) a /= q;
        }

        for (int p : prime) {
            if (p * p > a) break;
            if (a % p == 0) return new int[]{p, a / p};
        }

        return new int[]{1, a};
    }

    private List<Integer> sieve(int n) {
        boolean[] removed = new boolean[n + 1];
        for (int i = 2; i * i <= n; i++) {
            for (int j = i * i; j <= n; j += i) {
                removed[j] = true;
            }
        }

        List<Integer> prime = new LinkedList<>();
        prime.add(2);
        for (int i = 3; i <= n; i += 2) {
            if (!removed[i]) prime.add(i);
        }

        return prime;
    }

    private InputReader reader;
    private PrintWriter writer;

    public Solution(InputReader reader, PrintWriter writer) {
        this.reader = reader;
        this.writer = writer;
    }

    public static void main(String[] args) {
        InputReader reader = new InputReader(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        Solution solution = new Solution(reader, writer);
        solution.solve();

        writer.flush();
    }

    static class InputReader {
        private static final int BUFFER_SIZE = 1 << 20;

        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), BUFFER_SIZE);
            tokenizer = null;
        }

        public String nextToken() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException();
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }
    }
}