Problem: You are given an array a of length n that has a special condition: every element in this array has at most 7 divisors. Find the length of the shortest non-empty subsequence of this array product of whose elements is a perfect square.

A sequence a is a subsequence of an array b if a can be obtained from b by deletion of several (possibly, zero or all) elements.

Input

The first line contains an integer n (1 ≤ n ≤ 10^5) — the length of a.

The second line contains n integers a_1, a_2, …, a_{n} (1 ≤ a_i ≤ 10^6) — the elements of the array a.

Output

Output the length of the shortest non-empty subsequence of a product of whose elements is a perfect square. If there are several shortest subsequences, you can find any of them. If there's no such subsequence, print "-1".

Examples

Input


3
1 4 6


Output


1

Input


4
2 3 6 6


Output


2

Input


3
6 15 10


Output


3

Input


4
2 3 5 7


Output


-1

Note

In the first sample, you can choose a subsequence [1].

In the second sample, you can choose a subsequence [6, 6].

In the third sample, you can choose a subsequence [6, 15, 10].

In the fourth sample, there is no such subsequence.

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.*;
import java.math.*;
import java.awt.Point;
 
public class Main {
	static final long MOD = 998244353L;
	static final long INF = 1000000000000000007L;
	//static final long MOD = 1000000007L;
	//static final int INF = 1000000007;
	
	//static long[] factorial;
	
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter pw = new PrintWriter(System.out);
		HashMap<Integer,Integer> primes = new HashMap<Integer,Integer>();
		primes.put(1,0);
		boolean[] euclid = new boolean[1000001];
		int index = 1;
		for (int p = 2; p <= 1000000; p++) {
			if (! euclid[p]) {
				primes.put(p,index);
				index++;
				for (int i = 2*p; i <= 1000000; i += p) {
					euclid[i] = true;
				}
			}
		}
		
		ArrayList<Integer>[] graph = new ArrayList[primes.size()];
		for (int i = 0; i < graph.length; i++)
			graph[i] = new ArrayList<Integer>();
		
		int N = sc.ni();
		for (int i = 0; i < N; i++) {
			int n = sc.ni();
			for (int square = 1000; square >= 2; square--) {
				if (n % (square*square) == 0) {
					n /= (square*square);
					break;
				}
			}
			boolean pq = false;
			for (int p = 2; p*p <= n; p++) {
				if (n % p == 0) {
					int q = n/p;
					
					int n1 = primes.get(p);
					int n2 = primes.get(q);
					graph[n1].add(n2);
					graph[n2].add(n1);
					
					pq = true;
					break;
				}
			}
			
			if (!pq) {
				graph[0].add(primes.get(n));
				
				if (n>1)
					graph[primes.get(n)].add(0);
			}
		}
		
		int ans = shortest_cycle(graph);
		
		boolean two = false;
		checktwo:
		for (int i = 1; i < graph.length; i++) {
			Collections.sort(graph[i]);
			for (int j = 1; j < graph[i].size(); j++) {
				if (graph[i].get(j)==graph[i].get(j-1)) {
					two = true;
					break checktwo;
				}
			}
		}
		
		if (two)
			ans = Math.min(ans,2);
		
		if (ans == Integer.MAX_VALUE)
			pw.println(-1);
		else
			pw.println(ans);
		
		pw.close();
	}
	
	static int shortest_cycle(ArrayList<Integer>[] graph) { 
		//number of vertices is the number of primes
		int n = graph.length;
		
		// To store length of the shortest cycle 
		int ans = Integer.MAX_VALUE; 

		// For all vertices 
		for (int i = 0; i <= 168; i++) 
		{ 

			// Make distance maximum 
			int[] dist = new int[n]; 
			Arrays.fill(dist, (int) 1e9); 

			// Take a imaginary parent 
			int[] par = new int[n]; 
			Arrays.fill(par, -1); 

			// Distance of source to source is 0 
			dist[i] = 0; 
			ArrayDeque<Integer> q = new ArrayDeque<Integer>(); 

			// Push the source element 
			q.add(i); 

			// Continue until queue is not empty 
			while (!q.isEmpty()) 
			{ 

				// Take the first element 
				int x = q.poll(); 

				// Traverse for all it's childs 
				for (int child : graph[x]) 
				{ 
					// If it is not visited yet 
					if (dist[child] == (int) (1e9)) 
					{ 

						// Increase distance by 1 
						dist[child] = 1 + dist[x]; 

						// Change parent 
						par[child] = x; 

						// Push into the queue 
						q.add(child); 
					} else if (par[x] != child && par[child] != x) 
						ans = Math.min(ans, dist[x] + dist[child] + 1); 
				} 
			} 
		} 
		
		return ans;
	}
	
	public static long dist(long[] p1, long[] p2) {
		return (Math.abs(p2[0]-p1[0])+Math.abs(p2[1]-p1[1]));
	}
	
	//Find the GCD of two numbers
	public static long gcd(long a, long b) {
		if (a < b) return gcd(b,a);
		if (b == 0)
			return a;
		else
			return gcd(b,a%b);
	}
	
	//Fast exponentiation (x^y mod m)
	public static long power(long x, long y, long m) { 
		if (y < 0) return 0L;
		long ans = 1;
		x %= m;
		while (y > 0) { 
			if(y % 2 == 1) 
				ans = (ans * x) % m; 
			y /= 2;  
			x = (x * x) % m;
		} 
		return ans; 
	}
	
	public static int[] shuffle(int[] array) {
		Random rgen = new Random();
		for (int i = 0; i < array.length; i++) {
		    int randomPosition = rgen.nextInt(array.length);
		    int temp = array[i];
		    array[i] = array[randomPosition];
		    array[randomPosition] = temp;
		}
		return array;
	}
	
	public static long[] shuffle(long[] array) {
		Random rgen = new Random();
		for (int i = 0; i < array.length; i++) {
		    int randomPosition = rgen.nextInt(array.length);
		    long temp = array[i];
		    array[i] = array[randomPosition];
		    array[randomPosition] = temp;
		}
		return array;
	}
	
	public static int[][] shuffle(int[][] array) {
		Random rgen = new Random();
		for (int i = 0; i < array.length; i++) {
		    int randomPosition = rgen.nextInt(array.length);
		    int[] temp = array[i];
		    array[i] = array[randomPosition];
		    array[randomPosition] = temp;
		}
		return array;
	}
	
    public static int[][] sort(int[][] array) {
    	//Sort an array (immune to quicksort TLE)
 
		Arrays.sort(array, new Comparator<int[]>() {
			  @Override
        	  public int compare(int[] a, int[] b) {
				  //return a[0]-b[0]; //ascending order
				  if (a[1] != b[1]) {
					  return (a[1]-b[1]);
				  } else {
					  return (a[0]-b[0]);
				  }
	          }
		});
		return array;
	}
    
    public static long[][] sort(long[][] array) {
    	//Sort an array (immune to quicksort TLE)
		Random rgen = new Random();
		for (int i = 0; i < array.length; i++) {
		    int randomPosition = rgen.nextInt(array.length);
		    long[] temp = array[i];
		    array[i] = array[randomPosition];
		    array[randomPosition] = temp;
		}
		Arrays.sort(array, new Comparator<long[]>() {
			  @Override
        	  public int compare(long[] a, long[] b) {
				  if (a[0] < b[0])
					  return -1;
				  else if (a[0] > b[0])
					  return 1;
				  else
					  return 0;
	          }
		});
		return array;
	}
    
    static class FastScanner { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastScanner() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int ni() { 
            return Integer.parseInt(next()); 
        } 
  
        long nl() { 
            return Long.parseLong(next()); 
        } 
  
        double nd() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() {
            String str = ""; 
            try { 
                str = br.readLine(); 
            } catch (IOException e) {
                e.printStackTrace(); 
            } 
            return str;
        }
    }
}