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:
//package com.company;

import java.io.*;
import java.util.*;

public class Main {
    static long TIME_START, TIME_END;

    public static class Task {
        int N = 300001;

        public class Factor {
            int[] factors;
            List<Integer> primes;
            List<Integer>[] allDivisors;
            int[] mapToOnlyFactor;
            int[] mapToIndex;
            int[] toGetFactorCount;
            int M;

            public void reduceActiveSetSize(Set<Integer> activeNumbers) {
                List<Integer> toRemove = new ArrayList<>();
                for (int active : activeNumbers) {
                    int cost = getCount(active);
                    int ha = mapToIndex[active];
                    boolean remove = false;
                    if (active != 1 && cost >= toGetFactorCount[0] - 1) {
                        remove = true;
                    } else {
                        for (int l : allDivisors[ha]) {
                            int hl = mapToIndex[l];
                            if (toGetFactorCount[hl] <= cost) {
                                remove = true;
                                break;
                            }
                        }
                    }
                    if (remove) toRemove.add(active);
                }
                activeNumbers.removeAll(toRemove);
            }

            public boolean updateToGetFactor(int x, int cost) {
                int hx = mapToIndex[x];
                if (toGetFactorCount[hx] <= cost) return false;
                toGetFactorCount[hx] = cost;
                if (x != 1 && cost >= toGetFactorCount[0] - 1) return false;
                for (int l : allDivisors[hx]) {
                    int hl = mapToIndex[l];
                    if (toGetFactorCount[hl] <= cost) return false;
                }
                return true;
            }

            public int getCount(int x) {
                int hx = mapToIndex[x];
                return toGetFactorCount[hx];
            }

            public Factor() {
                factors = new int[N];
                primes = new ArrayList<>();
                for (int i = 2; i < N; i++) {
                    if (factors[i] == 0) {
                        factors[i] = i;
                        primes.add(i);
                    }
                    for (int j : primes) {
                        int y = i * j;
                        if (y >= N) break;
                        factors[y] = j;
                        if (i % j == 0) break;
                    }
                }
                Map<Integer, Integer> onlyFactors = new HashMap<>();
                mapToOnlyFactor = new int[N];
                for (int i = 1; i < N; i++) {
                    mapToOnlyFactor[i] = getOnlyFactor(i);
                    if (!onlyFactors.containsKey(mapToOnlyFactor[i]))
                        onlyFactors.put(mapToOnlyFactor[i], M++);
                }
                mapToIndex = new int[N];
                for (int i = 1; i < N; i++) {
                    mapToIndex[i] = onlyFactors.get(mapToOnlyFactor[i]);
                }
                allDivisors = new List[M];
                for (Map.Entry<Integer, Integer> numberAndIdx: onlyFactors.entrySet()) {
                    allDivisors[numberAndIdx.getValue()] = getAllDivisors(numberAndIdx.getKey());
                }
                toGetFactorCount = new int[M];
                int inf = Integer.MAX_VALUE / 2;
                Arrays.fill(toGetFactorCount, inf);
            }

            public List<Integer> getAllDivisors(int x) {
                List<Integer> primeDivisors = new ArrayList<>();
                while (x != 1) {
                    int v = factors[x];
                    primeDivisors.add(v);
                    while (x % v == 0) x /= v;
                }
                int n = primeDivisors.size();
                List<Integer> allDivisors = new ArrayList<>();
                for (int i = 1; i < (1 << n) - 1; i++) {
                    int y = 1;
                    for (int j = 0; j < n; j++) {
                        if ((i & (1 << j)) != 0) y *= primeDivisors.get(j);
                    }
                    allDivisors.add(y);
                }
                return allDivisors;
            }

            public int getOnlyFactor(int x) {
                int y = 1;
                while (x != 1) {
                    int v = factors[x];
                    y *= v;
                    while (x % v == 0) x /= v;
                }
                return y;
            }
        }

        public int gcd(int a, int b) {
            while (b != 0) {
                a = a % b;
                int t = b;
                b = a;
                a = t;
            }
            return a;
        }

        public void solve(Scanner sc, PrintWriter pw) throws IOException {
            Factor f = new Factor();
            int[] allNumbers = new int[N];
            int n = sc.nextInt();
            for (int i = 0; i < n; i++) {
                int a = sc.nextInt();
                allNumbers[a] = 1;
            }
            List<Integer> numbers = new ArrayList<>();
            for (int i = 0; i < N; i++) {
                if (allNumbers[i] == 1) {
                    numbers.add(i);
                }
            }
            Collections.shuffle(numbers);
            int maximumSubsetSize = 7;

            Set<Integer> activeNumbers = new HashSet<>();
            int fresh = 0;

            for (int number : numbers) {
                f.updateToGetFactor(number, 1);
                List<Integer> pendingAdd = new ArrayList<>();
                pendingAdd.add(number);
                for (int active : activeNumbers) {
                    int gcd = gcd(active, number);
                    int cost = f.getCount(active) + 1;
                    if (cost > maximumSubsetSize ||  f.updateToGetFactor(gcd, cost)) {
                        pendingAdd.add(gcd);
                    }
                }
                activeNumbers.addAll(pendingAdd);
                if (activeNumbers.size() > 50) {
                    if (activeNumbers.size() > 500 || fresh == 0) {
                        fresh = 10;
                        f.reduceActiveSetSize(activeNumbers);
                    } else {
                        fresh--;
                    }
                }
            }
            pw.println(f.getCount(1) > maximumSubsetSize ? -1 : f.getCount(1));
        }
    }

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
//        Scanner sc = new Scanner(new FileInputStream("Test.in"));
        PrintWriter pw = new PrintWriter(System.out);
//        PrintWriter pw = new PrintWriter(new FileOutputStream("Test.in"));
//        PrintWriter pw = new PrintWriter(new FileOutputStream("Test.out"));
//        int n = 300000;
//        int sy = 2 * 3 * 5 * 7 * 11;
//        pw.println(n);
//        Random rnd = new Random();
//        for (int i = 0; i < n - 11; i++) {
//            pw.println(rnd.nextInt(n / sy - 1) * sy + sy);
//        }
//        pw.println(2 * 3 * 5 * 7);
//        pw.println(2 * 3 * 5 * 11);
//        pw.println(2 * 3 * 7 * 11);
//        pw.println(2 * 5 * 7 * 11);
//        pw.println(3 * 5 * 7 * 11);
//
//        pw.println(3 * 5 * 7 * 11 * 13);
//        pw.println(3 * 5 * 7 * 11 * 17);
//        pw.println(3 * 5 * 7 * 11 * 19);
//        pw.println(3 * 5 * 7 * 11 * 23);
//        pw.println(3 * 5 * 7 * 11 * 29);
//
//        pw.println(3 * 5 * 7);
//
//        pw.close();

        Runtime runtime = Runtime.getRuntime();
        long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
        TIME_START = System.currentTimeMillis();
        Task t = new Task();
        t.solve(sc, pw);
        TIME_END = System.currentTimeMillis();
        long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
        pw.close();
        System.out.println("Memory increased:" + (usedMemoryAfter - usedMemoryBefore) / 1000000);
        System.out.println("Time used: " + (TIME_END - TIME_START) + ".");
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader s) throws FileNotFoundException {
            br = new BufferedReader(s);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }
}