You are given n integer numbers a_1, a_2, ..., a_n. Consider graph on n nodes, in which nodes i, j (i≠ j) are connected if and only if, a_i AND a_j≠ 0, where AND denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND).

Find the length of the shortest cycle in this graph or determine that it doesn't have cycles at all.

Input

The first line contains one integer n (1 ≤ n ≤ 10^5) — number of numbers.

The second line contains n integer numbers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^{18}).

Output

If the graph doesn't have any cycles, output -1. Else output the length of the shortest cycle.

Examples

Input


4
3 6 28 9


Output


4

Input


5
5 12 9 16 48


Output


3

Input


4
1 2 4 8


Output


-1

Note

In the first example, the shortest cycle is (9, 3, 6, 28).

In the second example, the shortest cycle is (5, 12, 9).

The graph has no cycles in the third example.
import java.io.*;
import java.util.*;
 
public class codeforces2 { // in case I want to work on more than 1 problem at a time
	public static PrintWriter out;
	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;
		public MyScanner() {
			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 nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			}
			catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
	// The next two void functions are shuffle functions on an array.
	// This way, quick sort encounters the worst case scenario with low probability.
	// A reason for doing this is if we don't a primitive data array to an object array.
	// For safety reasons, it would be preferable to use object arrays unless doing so expends a lot of time.
	public static void shuffleLongArray(long[] arr) {
		int n = arr.length;
		Random rnd = new Random();
        for (int i=0; i < n; i++) {
        	long tmp = arr[i];
        	int randomPos = i + rnd.nextInt(n-i);
        	arr[i] = arr[randomPos];
        	arr[randomPos] = tmp;
        }
	}
	public static void shuffleIntArray(int[] arr) {
		int n = arr.length;
		Random rnd = new Random();
        for (int i=0; i < n; i++) {
        	int tmp = arr[i];
        	int randomPos = i + rnd.nextInt(n-i);
        	arr[i] = arr[randomPos];
        	arr[randomPos] = tmp;
        }
	}
 
	public static void main (String[] args) throws IOException {
    	MyScanner sc = new MyScanner();
    	out = new PrintWriter(new BufferedOutputStream(System.out));
    	// Write solution here.
    	int n = sc.nextInt();
    	int m = n;
    	long[] modes = new long[n];
    	for (int i=0; i < n; i++) {
    		modes[i] = sc.nextLong();
    		if (modes[i]==0) m--;
    	}
    	long[] nodes = new long[m];
    	int counter = 0;
    	for (int i=0; i < n; i++) {
    		if (modes[i] != 0) {
    			nodes[counter] = modes[i];
    			counter++;
    		}
    	}
    	n = m;
    	if (n > 120) out.println(3);
    	else { // we can afford O(N^4) solutions
    		int cyclic = 99999999;
    		int[][] adj = new int[n][n];
    		for (int i=0; i < n; i++) {
    			for (int j=0; j < n; j++) {
    				if (i == j) continue;
    				long u = nodes[i] & nodes[j];
    				if (u != 0) adj[i][j] = 1;
    			}
    		}
    		// adjacency matrix sanity check
    		/*
    		for (int i=0; i < n; i++) {
    			for (int j=0; j < n; j++) {
    				out.print(adj[i][j] + " ");
    			}
    			out.println();
    		}
    		*/
    		int[] degs = new int[n];
    		for (int i=0; i < n; i++) {
    			int spread = 0;
    			for (int j=0; j < n; j++) {
    				spread += adj[i][j];
    			}
    			degs[i] = spread;
    		}
    		int[][] levels = new int[n][n];
    		int out = 0;
    		for (int s=0; s < n; s++) {
    			out = 0;
    			// System.out.println("Origin: " + s);
    			int[][] cheek = new int[n+3][n];
    			Deque<Integer> deque = new ArrayDeque<Integer>();
    			deque.add(s);
    			while (!deque.isEmpty()) {
    				if (out > 0) break;
    				int current = deque.removeLast();
    				int lvl = levels[s][current];
    				if (lvl >= cyclic) break;
    				for (int z=0; z < n; z++) {
    					if (adj[current][z] == 0) continue;
    					else if (z==s && lvl + 1 < 3) continue;
    					else if (z==s) {
    						int y = lvl + 1;
    						if (y < cyclic) cyclic = y;
    						out = 1;
    						break;
    					}
    					else {
    						// special case
    						if (lvl > 1) {
        						int leg = 0;
        						for (int j=0; j < n; j++) {
        							if (adj[current][j]==1 && cheek[lvl-1][j] > 0) leg++;
        						}
        						if (levels[s][z]==lvl-1 && leg <= 1) continue;
    						}
    						/*
    						if (lvl == 2) {
    							int leg = 0;
    							for (int j=0; j < n; j++) {
    								if (adj[current][j]==1 && cheek[j]==1) leg++;
    							}
    							if (levels[s][z]==1) {
    								if (leg <= 1) continue;
    							}
    						}
    						*/
    						levels[s][z] = lvl + 1;
    						deque.push(z);
    						cheek[levels[s][z]][z] = 1;
    						// System.out.println("Level " + (lvl + 1) + ": " + z);
    					}
    				}
    			}    			
    		}
    		if (cyclic > 1000) System.out.println(-1);
    		else System.out.println(cyclic);
    	}
    	out.close();
	}
}