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 Main {

    static FastReader in;
    static PrintWriter out;
    static Random rand = new Random();
    static final int INF = (int) (1e9 + 10);
    static final int MOD = (int) (1e9 + 7);
    static final int N = (int) (1e6);
    static final int LOGN = 62;
    static int n, m = 0;
    static int[] a, lp, primes, ind, d, p;
    static HashSet<Integer> set;
    static ArrayList<Integer>[] g;
    static ArrayDeque<Integer> q;

    static void solve() {
        n = in.nextInt();

        a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }

        lp = new int[N + 1]; lp[1] = 1;
        primes = new int[N + 1]; primes[0] = 1;
        ind = new int[N + 1]; primes[1] = m++;
        for (int i = 2; i <= N; i++) {
            if (lp[i] == 0) {
                lp[i] = i;
                primes[m] = i;
                ind[i] = m++;
                if ((long) i * i > N) continue;
                for (int j = i * i; j <= N; j += i) {
                    if (lp[j] == 0) lp[j] = i;
                }
            }
        }

        set = new HashSet<>();
        g = new ArrayList[m];
        Arrays.setAll(g, gg -> new ArrayList<>());
        for (int i = 0; i < n; i++) {
            int sq = (int) Math.sqrt(a[i]);
            if (sq * sq == a[i]) {
                out.println(1);
                return;
            }
            int aa = a[i];
            int v = lp[aa], u = 1;
            int cnt = 0;
            while (lp[aa] == v) {
                cnt++;
                aa /= lp[aa];
            }
            if (cnt % 2 == 0) v = 1;
            if (aa > 1) {
                u = lp[aa];
                cnt = 0;
                while (lp[aa] == u) {
                    cnt++;
                    aa /= lp[aa];
                }
                if (cnt % 2 == 0) u = 1;
            }
            g[ind[v]].add(ind[u]);
            g[ind[u]].add(ind[v]);
            set.add(v * u);
        }
        if (set.size() != n) {
            out.println(2);
            return;
        }

        int ans = INF;
        int sq = (int) Math.ceil(Math.sqrt(N));
        q = new ArrayDeque<>();
        d = new int[m];
        p = new int[m];
        for (int i = 1; i <= sq; i++) {
            if (lp[i] != i) continue;
            for (int v = 0; v < m; v++) {
                d[v] = -1;
                p[v] = -1;
            }
            int v = ind[i];
            q.addLast(v);
            d[v] = 0;
            p[v] = v;
            while (!q.isEmpty()) {
                v = q.pollFirst();
                if (d[v] + 1 >= ans) {
                    q.clear();
                    break;
                }
                for (int u : g[v]) {
                    if (d[u] == -1) {
                        d[u] = d[v] + 1;
                        p[u] = v;
                        q.addLast(u);
                    } else if (p[v] != u) {
                        ans = Math.min(ans, d[v] + d[u] + 1);
                    }
                }
            }
        }

        if (ans == INF) {
            out.println(-1);
        } else {
            out.println(ans);
        }
    }

    public static void main(String[] args) throws FileNotFoundException {
        in = new FastReader(System.in);
//        in = new FastReader(new FileInputStream("connect.in"));
        out = new PrintWriter(System.out);
//        out = new PrintWriter(new FileOutputStream("connect.out"));


        int q = 1;
//        q = in.nextInt();

        while (q-- > 0) {
            solve();
        }

        out.close();
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        Integer nextInt() {
            return Integer.parseInt(next());
        }

        Long nextLong() {
            return Long.parseLong(next());
        }

        Double nextDouble() {
            return Double.parseDouble(next());
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(nextLine());
            }
            return st.nextToken();
        }

        String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }
    }
}