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.Arrays;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskF {
        private static final int NUMBER_RANGE = 300001;
        private static final int DIVISOR_RANGE = 8;
        int[][] factors;
        int[] divisors;
        int[] bit;
        boolean[] isPrime;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            factors = new int[NUMBER_RANGE][DIVISOR_RANGE];
            divisors = new int[NUMBER_RANGE];

            int[] sum = new int[NUMBER_RANGE];

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

            isPrime = new boolean[NUMBER_RANGE];
            Arrays.fill(isPrime, true);
            isPrime[0] = isPrime[1] = false;
            for (int i = 1; i < NUMBER_RANGE; ++i) {
                for (int j = i; j < NUMBER_RANGE; j += i) {
                    divisors[i] += sum[j];
                }
            }

            for (int i = 2; i < NUMBER_RANGE; ++i) {
                for (int j = i; j < NUMBER_RANGE; j += i) {
                    if (i != j) {
                        isPrime[j] = false;
                    }

                    if (isPrime[i]) {
//                    if (factors[j][0] == factors[j].length) System.err.println(Arrays.toString(factors[j]));
//                    if (factors[j][0] > 8) System.err.println(Arrays.toString(factors[j]));
                        factors[j][++factors[j][0]] = i;
                    }
                }
            }

//        out.println(isPrime[5]);

            bit = new int[1 << 7];
            for (int i = 0; i < 7; ++i) {
                bit[1 << i] = i;
            }

            int[] needed = new int[NUMBER_RANGE];
            Arrays.fill(needed, 0x3F3F3F3F);
            for (int i = 0; i < n; ++i) {
                int prod = 1;

                int[] curFact = factors[a[i]];
                for (int j = 0; j < curFact[0]; ++j) {
                    prod *= curFact[j + 1];
                }
                needed[prod] = 0;
            }

//        out.println(needed[1]);

            int[] dp = new int[1 << 7];
            int[] prod = new int[1 << 7];
            for (int i = NUMBER_RANGE - 1; i > 1; --i) {
                if (needed[i] == 0x3F3F3F3F) {
                    continue;
                }
                int numFactors = factors[i][0];
                int[] curFact = factors[i];

                prod[0] = 1;
                for (int j = 1; j < (1 << numFactors); ++j) {
                    int lb = j & -j;
                    prod[j] = prod[j - lb] * curFact[bit[lb] + 1];
                }

//            if (i == 2) out.println(Arrays.toString(curFact));

                for (int j = 0; j < (1 << numFactors); ++j) {
                    dp[j] = divisors[prod[j]];
                }

                for (int k = 0; k < numFactors; ++k) {
                    for (int j = 0; j < (1 << numFactors); ++j) {
                        if (((j >> k) & 1) != 0) continue;
                        dp[j] -= dp[j ^ (1 << k)];
                    }
                }

                int[] factdp = new int[1 << numFactors];
                for (int j = 0; j < (1 << numFactors); ++j) {
                    factdp[j] = dp[j];
                }
//            if (i == 2) out.println("dp = " + Arrays.toString(factdp));
//            if (needed[1] < 100) out.println("needed[1] = " + needed[1] + ", i = " + i);

                for (int j = 0; j < (1 << numFactors); ++j) {
                    assert dp[j] >= 0;
                    if (dp[j] != 0) {
                        needed[prod[j]] = Math.min(needed[prod[j]], needed[i] + 1);
                    }
                }
            }

            if (needed[1] == 0x3F3F3F3F) {
                needed[1] = -1;
            } else {
                ++needed[1];
            }
            out.println(needed[1]);
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

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

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

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

    }
}