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

public class F {
	
	static boolean debug=false;
	
	static int[] factorOf=new int[300_001];
	static HashMap<Hash, Integer> countOfHash=new HashMap<>();
	static int n;
	
	public static void main(String[] args) {
		precomp();
		
		FastScanner fs=new FastScanner();
		n=fs.nextInt();
		HashSet<Integer> set=new HashSet<>();
		for (int i=0; i<n; i++) set.add(fs.nextInt());
		n=0;
		int[] givenNumbers=new int[set.size()];
		for (int i:set)
			givenNumbers[n++]=i;
		
		//make sure it will take more than one move and is possible
		int allGCD=givenNumbers[0];
		for (int i:givenNumbers) {
			if (i==1) {
				System.out.println(1);
				return;
			}
			allGCD=gcd(allGCD, i);
		}
		if (allGCD!=1) {
			System.out.println(-1);
			return;
		}
		
		//build all the hashes
		int[][] factors=new int[n][];
		for (int i=0; i<n; i++) {
			factors[i]=getFactors(givenNumbers[i]);
			for (int m=0; m<1<<factors[i].length; m++) {
				Hash hash=new Hash();
				for (int factIndex=0; factIndex<factors[i].length; factIndex++) {
					if ((m&(1<<factIndex))==0)
						continue;
					hash.add(factors[i][factIndex]);
				}
				countOfHash.put(hash, countOfHash.getOrDefault(hash, 0)+1);
			}
		}
		
		if (debug) System.out.println("Can remove 5: "+canDirectlyRemove(new int[] {5}));
		
		if (debug) System.out.println("Given numbers "+Arrays.toString(givenNumbers));
		int best=Integer.MAX_VALUE;
		outer:for (int startIndex=0; startIndex<n; startIndex++) {
			if (debug) System.out.println("Trying startIndex: "+startIndex);
			int[] toRemove=factors[startIndex];
			if (debug) System.out.println("\tToRemove: "+Arrays.toString(toRemove));
			int[] stepsToRemove=new int[1<<toRemove.length];
			for (int maskToRemove=1; maskToRemove<1<<toRemove.length; maskToRemove++) {
				int[] arrayToKill=new int[Integer.bitCount(maskToRemove)];
				int spotInArrayToKill=0;
				for (int i=0; i<toRemove.length; i++) {
					if ((maskToRemove&(1<<i))==0)
						continue;
					arrayToKill[spotInArrayToKill++]=toRemove[i];
				}
				if (canDirectlyRemove(arrayToKill)) {
					if (debug)System.out.println("\tCan directly remove "+Integer.toBinaryString(maskToRemove));
					stepsToRemove[maskToRemove]=1;
					continue;
				}
				stepsToRemove[maskToRemove]=999;
				
				for (int submask=maskToRemove-1; submask>0; submask=(submask-1)&maskToRemove) {
					stepsToRemove[maskToRemove]=Math.min(stepsToRemove[maskToRemove], stepsToRemove[submask]+stepsToRemove[maskToRemove^submask]);
				}
				if (stepsToRemove[maskToRemove]>=999) {
					//then it is completely impossible to remove this number
					continue outer;
				}
			}
			best=Math.min(best, stepsToRemove[(1<<toRemove.length)-1]);
		}
		System.out.println(best+1);
	}

	static boolean canDirectlyRemove(int[] toRemove) {
		int total=n;
		for (int mask=1; mask<1<<toRemove.length; mask++) {
			Hash h=new Hash();
			for (int i=0; i<toRemove.length; i++) {
				if ((mask&(1<<i))==0)
					continue;
				h.add(toRemove[i]);
			}
			if (Integer.bitCount(mask)%2==0) {
				total+=countOfHash.getOrDefault(h, 0);
			}
			else {
				total-=countOfHash.getOrDefault(h, 0);
			}
		}
		return total>0;
	}
	
	static boolean canRemoveHash(Hash h) {
		return countOfHash.getOrDefault(h, 0)<n;
	}
	
	static void precomp() {
		int n=factorOf.length;
		Arrays.fill(factorOf, -1);
		for (int i=2; i<n; i++) {
			if (factorOf[i]!=-1)
				continue;
			for (int j=i; j<n; j+=i)
				factorOf[j]=i;
		}
	}
	
	static int[] getFactors(int n) {
		HashSet<Integer> facts=new HashSet<>();
		while (n!=1) {
			facts.add(factorOf[n]);
			n/=factorOf[n];
		}
		int[] array=new int[facts.size()];
		int i=0;
		for (int f:facts)
			array[i++]=f;
		Arrays.sort(array);
		return array;
	}
	
	static class Hash implements Comparable<Hash> {
		int m1=1_000_000_007;
		int m2=1_000_000_009;
		int m3=8675_309;
		
		long v1=0, v2=0, v3=0;
		
		int s1=613;
		int s2=277;
		int s3=1051;
		
		public void add(int i) {
			v1=(v1*s1+i)%m1;
			v2=(v2*s2+i)%m2;
			v3=(v3*s3+i)%m3;
		}
		
		public boolean equals(Object oo) {
			Hash o=(Hash)oo;
			return v1==o.v1&&v2==o.v2&&v3==o.v3;
		}
		
		public int hashCode() {
			return (int)v1;
		}
		
		public int compareTo(Hash o) {
			if (v1!=o.v1) return Long.compare(v1, o.v1);
			if (v2!=o.v2) return Long.compare(v2, o.v2);
			return Long.compare(v3, o.v3);
		}
	}
	
	static int gcd(int a, int b) {
		return b==0?a:gcd(b, a%b);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		
		public String next() {
			while (!st.hasMoreElements())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
		
		public int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) {
				a[i]=nextInt();
			}
			return a;
		}
		
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		
	}

}