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.util.*;
public class MakeItOne {
	static int LIM = 300001;
	public static void main (String [] arg) throws Throwable {
		int [] sieveprimes = new int [LIM];
		int [] factorization = new int [LIM+1];
		int [] prev = new int [LIM+1];
		int [] primecount = new int [LIM+1];
		boolean [] composite = new boolean [LIM+1];
		int primeptr = 0;
		for (int j = 2; j<=LIM; j++) {
			if (composite[j]) {
				int p = factorization[j];
				int j2 = j;
				while (j2> 0 && j2 % p == 0) j2 /=p;
				primecount[j] = 1 + primecount[j2];
				prev[j] = j2;
				continue;
			}
			factorization[j] = j;
			primecount[j] = 1;
			sieveprimes[primeptr++] = j;
			for (int k = j+j; k<=LIM; k+=j) {
				composite[k] = true;
				factorization[k] = j;
			}
		}
		int n = (int)nextLong();
		int [] score = new int [n];
		int [] primes = new int [7];
		int [] inputcount = new int [LIM];
		boolean [] used = new boolean [LIM];
		
		int pptr = 0;
		
		int MINSCORE = Integer.MAX_VALUE;
		int MINPRIME = Integer.MAX_VALUE;
		for (int i = 0; i<n; ++i) {
			score[i] = (int)nextLong();
			if (score[i] == 1) { System.out.println(1); return;}
			int N = score[i];
			while (N != 1) {
				int p = factorization[N];
				inputcount[p]++;
				while (N % p == 0) N/= p;
			}
		}
		int pmax = 2;
		int MAXCNT = inputcount[2];
		for (int i = 3; i<inputcount.length; i+=2) if (!composite[i] && inputcount[i] > MAXCNT) { 
			MAXCNT = inputcount[i];
			pmax = i;
		}
		boolean found = false;
		int ANS = 7;
		int loops = 0;
		for (int ii = 0; ii<n && ANS > 2; ++ii) {
			if (score[ii] % pmax == 0) continue;
			
			int N = score[ii];
			int PROD = 1;
			pptr = 0;
			while (N != 1) {
				int p = factorization[N];
				PROD *= p;
				primes[pptr++] = p;
				while (N % p == 0) N/= p;
			}
			if (used[PROD]) continue;
			used[PROD] = true;
			
			
			loops++;	
			boolean [] bitmask = new boolean [1<<pptr];
			for (int i = 0; i<n; ++i) {
				int MASK = 0;
				for (int j = 0; j<pptr; ++j) {
					if (score[i] % primes[j] == 0)
						MASK = MASK | (1<<j);
				}
				bitmask[MASK] = true;
			}
			int MASK = (1<<pptr) - 1;
			for (int i = 0; i<bitmask.length; ++i) {
			 if (!bitmask[i]) continue;
			 if ((MASK & i) == 0) ANS = Math.min(ANS, 2);
			 for (int j = i+1; j<bitmask.length && ANS > 3; ++j) {
				if (!bitmask[j]) continue;
				if ((MASK & i & j) == 0) ANS = Math.min(ANS, 3);
				for (int k = j+1; k<bitmask.length && ANS > 4; ++k) {
					if (!bitmask[k]) continue;
					if ((MASK & i & j & k) == 0) ANS = Math.min(ANS, 4);
					for (int L=k+1; L<bitmask.length && ANS > 5; ++L) {
						if (!bitmask[L]) continue;
						if ((MASK & i & j & k & L) == 0) ANS = Math.min(ANS, 5);
						for (int M=L+1; M<bitmask.length && ANS > 6; ++M) {
							if (!bitmask[M]) continue;
							if ((MASK & i & j & k & L & M) == 0) ANS = Math.min(ANS, 6);
						}
					}
				}
			 }
			}
			found = true;
			break;
		}
		if (!found) {System.out.println(-1); return;}
		System.out.println(ANS);
	}

	
	public static long nextLong() throws Throwable {
		long i = System.in.read();
		boolean neg = false;
		while (i < 45) i = System.in.read();
		if (i == 45) {neg=true;i=48;}
		i = i - 48;
		long j = System.in.read();
		while (j > 32) {
			i*=10;
			i+=j-48;
			j = System.in.read();
		}
		return (neg) ? -i : i;
	}
}