Problem: Janusz is a businessman. He owns a company "Januszex", which produces games for teenagers. Last hit of Januszex was a cool one-person game "Make it one". The player is given a sequence of n integers a_i.

It is allowed to select any subset of them, and the score is equal to the greatest common divisor of selected elements. The goal is to take as little elements as it is possible, getting the score 1. Now Janusz wonders, for given sequence, how much elements should the player choose?

Input

The first line contains an only integer n (1 ≤ n ≤ 300 000) — the number of integers in the sequence.

The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 300 000).

Output

If there is no subset of the given sequence with gcd equal to 1, output -1.

Otherwise, output exactly one integer — the size of the smallest subset with gcd equal to 1.

Examples

Input

3
10 6 15


Output

3


Input

3
2 4 6


Output

-1


Input

7
30 60 21 42 70 15 30


Output

3

Note

In the first example, selecting a subset of all numbers gives a gcd of 1 and for all smaller subsets the gcd is greater than 1.

In the second example, for all subsets of numbers the gcd is at least 2. 

Solution (in JAVA):

Solution:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Vadim
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskF solver = new TaskF();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskF {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.ni();
            int[] a = in.na(n);
            int MAX_VAL = 300007;
            ArrayList<Integer> pr = new ArrayList<>(MAX_VAL);
            int[] lp = new int[MAX_VAL];
            IntegerUtils.sieve(MAX_VAL - 5, pr, lp);
            int[][] divs = new int[MAX_VAL][10];
            int[] ndivs = new int[MAX_VAL];

            int[] count = new int[MAX_VAL];
            boolean[] res = new boolean[MAX_VAL];
            for (int i = 0; i < n; i++) {
                int[] curDivs = new int[10];
                int num = a[i];
                int ndiv = 0;
                int repl = 1;
                while (num > 1) {
                    int div = lp[num];
                    curDivs[ndiv++] = div;
                    while (num % div == 0)
                        num /= div;
                    repl *= div;
                }
                a[i] = repl;
                divs[repl] = curDivs;
                ndivs[repl] = ndiv;
                res[repl] = true;
            }
            n = 0;
            for (int i = 0; i < MAX_VAL; i++) {
                if (res[i])
                    a[n++] = i;
            }
            for (int i = 0; i < n; i++) {
                int[] curDivs = divs[a[i]];
                int ndiv = ndivs[a[i]];
                for (int mask = 0; mask < 1 << ndiv; mask++) {
                    int num = 1;
                    for (int bit = 0; bit < ndiv; bit++) {
                        if ((mask & 1 << bit) != 0) {
                            num *= curDivs[bit];
                        }
                    }
                    count[num]++;
                }
            }
            int[] curCount = new int[MAX_VAL];
            int ans = Integer.MAX_VALUE;
            for (int i = 0; i < n; i++) {
                int[] curDivs = divs[a[i]];
                int k = ndivs[a[i]];
                for (int mask = (1 << k) - 1; mask >= 0; mask--) {
                    int num = 1;
                    for (int bit = 0; bit < k; bit++) {
                        if ((mask & 1 << bit) != 0)
                            num *= curDivs[bit];
                    }
                    curCount[mask] = count[num];
                    for (int smask = 0; smask < 1 << k; smask++) {
                        if ((mask | smask) == smask && smask > mask) {
                            curCount[mask] -= curCount[smask];
                        }
                    }
                }
                int[] dp = new int[1 << k];
                for (int j = 0; j < 1 << k; j++) {
                    dp[j] = Integer.MAX_VALUE;
                }
                dp[(1 << k) - 1] = 1;
                for (int mask = (1 << k) - 1; mask >= 0; mask--) {
                    if (dp[mask] < Integer.MAX_VALUE)
                        for (int smask = 0; smask < 1 << k; smask++) {
                            if (curCount[smask] > 0)
                                dp[smask & mask] = Math.min(dp[smask & mask], dp[mask] + 1);
                        }
                }
                ans = Math.min(ans, dp[0]);

            }
            if (ans == Integer.MAX_VALUE)
                ans = -1;
            out.println(ans);
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String ns() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(ns());
        }

        public int[] na(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = ni();
            return a;
        }

    }

    static class IntegerUtils {
        public static void sieve(int n, ArrayList<Integer> pr, int[] lp) {
            for (int i = 2; i < n + 1; i++) {
                if (lp[i] == 0) {
                    lp[i] = i;
                    pr.add(i);
                }
                int j = 0;
                while (j < pr.size() && pr.get(j) <= lp[i] && i * pr.get(j) <= n) {
                    lp[i * pr.get(j)] = pr.get(j);
                    j++;
                }
            }
        }

    }
}