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.
/**
 * BaZ :D
 */

import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main
{
    static MyScanner scan;
    static PrintWriter pw;
    static long MOD = 1_000_000_007;
    static long INF = 1_000_000_000_000_000_000L;
    static long inf = 2_000_000_000;
    public static void main(String[] args) {
        new Thread(null,null,"BaZ",1<<27)
        {
            public void run()
            {
                try
                {
                    solve();
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                    System.exit(1);
                }
            }
        }.start();
    }
    static int n, baap[], weight[],dis[];
    static HashSet<Integer> adj[];
    static void solve() throws IOException
    {
        //initIo(true);
        initIo(false);
        StringBuilder sb = new StringBuilder();
        n = ni();
        adj = new HashSet[n+1];
        for(int i=1;i<=n;++i) {
            adj[i] = new HashSet<>();
        }
        long arr[] = new long[n+1];
        for(int i=1;i<=n;++i) {
            arr[i] = nl();
        }
        for(int bit=0;bit<=60;++bit) {
            int cnt = 0;
            for(int i=1;i<=n;++i) {
                if((arr[i]&(1L<<bit))!=0) {
                    cnt++;
                }
            }
            if(cnt>2) {
                pl(3);
                System.exit(0);
            }
        }

        for(int bit=0;bit<=60;++bit) {
            int prev = -1;
            for(int i=1;i<=n;++i) {
                if((arr[i]&(1L<<bit))!=0) {
                    if(prev!=-1) {
                        adj[prev].add(i);
                        adj[i].add(prev);
                    }
                    prev = i;
                }
            }
        }
//        pl("Graph: ");
//        for(int i=1; i<=n; ++i) {
//            pl("i: "+i);
//            for(int e : adj[i]) {
//                if(e>i) {
//                    p(e);
//                }
//            }
//            pl();
//        }
        init(n);
        ArrayList<Integer> isCyclex = new ArrayList<>();
        ArrayList<Integer> isCycley = new ArrayList<>();
        for(int i=1;i<=n;++i) {
            for(int e : adj[i]) {
                if(e<i) {
                    continue;
                }
                if(!un(i, e)) {
                    isCyclex.add(i);
                    isCycley.add(e);
                }
            }
        }
        if(isCyclex.isEmpty()) {
            pl(-1);
        }
        else {
            int ans = 1000000;
            dis = new int[n+1];
            for(int i=0;i<isCyclex.size();++i) {
                Arrays.fill(dis, -1);
                //pl("Is a cycle: "+ isCyclex.get(i)+ " , " + isCycley.get(i));
                adj[isCyclex.get(i)].remove(isCycley.get(i));
                adj[isCycley.get(i)].remove(isCyclex.get(i));
                bfs(isCyclex.get(i));
                ans = min(ans, dis[isCycley.get(i)]);
                //pl("Dis was : "+dis[isCycley.get(i)]);
                adj[isCyclex.get(i)].add(isCycley.get(i));
                adj[isCycley.get(i)].add(isCyclex.get(i));
            }
            pl(ans+1);
        }
        pw.flush();
        pw.close();
    }
    static void bfs(int e) {
        dis[e] = 0;
        LinkedList<Integer> q = new LinkedList<>();
        q.add(e);
        while(!q.isEmpty()) {
            int curr = q.poll();
            for(int f : adj[curr]) {
                if(dis[f]==-1) {
                    dis[f] = dis[curr] + 1;
                    q.add(f);
                }
            }
        }
    }
    static void init(int n)
    {
        baap = new int[n+1];
        weight = new int[n+1];
        for(int i=0;i<=n;++i)
        {
            baap[i] = i;
            ++weight[i];
        }
    }
    static int gr(int a)
    {
        if(baap[a]==a)
            return a;
        return baap[a] = gr(baap[a]);
    }
    static boolean un(int a,int b)
    {
        int ra = gr(a);
        int rb = gr(b);
        if(ra==rb)
            return false;
        if(weight[rb]>weight[ra])
        {
            weight[rb]+=weight[ra];
            baap[ra] = rb;
        }
        else
        {
            weight[ra]+=weight[rb];
            baap[rb] = ra;
        }
        return true;
    }

    static void initIo(boolean isFileIO) throws IOException {
        scan = new MyScanner(isFileIO);
        if(isFileIO) {
            pw = new PrintWriter("/Users/amandeep/Desktop/output.txt");
        }
        else {
            pw = new PrintWriter(System.out, true);
        }
    }
    static int ni() throws IOException
    {
        return scan.nextInt();
    }
    static long nl() throws IOException
    {
        return scan.nextLong();
    }
    static double nd() throws IOException
    {
        return scan.nextDouble();
    }
    static String ne() throws IOException
    {
        return scan.next();
    }
    static String nel() throws IOException
    {
        return scan.nextLine();
    }
    static void pl()
    {
        pw.println();
    }
    static void p(Object o)
    {
        pw.print(o+" ");
    }
    static void pl(Object o)
    {
        pw.println(o);
    }
    static void psb(StringBuilder sb)
    {
        pw.print(sb);
    }
    static void pa(String arrayName, Object arr[])
    {
        pl(arrayName+" : ");
        for(Object o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, int arr[])
    {
        pl(arrayName+" : ");
        for(int o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, long arr[])
    {
        pl(arrayName+" : ");
        for(long o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, double arr[])
    {
        pl(arrayName+" : ");
        for(double o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, char arr[])
    {
        pl(arrayName+" : ");
        for(char o : arr)
            p(o);
        pl();
    }
    static void pa(String listName, List list)
    {
        pl(listName+" : ");
        for(Object o : list)
            p(o);
        pl();
    }
    static void pa(String arrayName, Object[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(Object o : arr[i])
                p(o);
            pl();
        }
    }
    static void pa(String arrayName, int[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(int o : arr[i])
                p(o);
            pl();
        }
    }
    static void pa(String arrayName, long[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(long o : arr[i])
                p(o);
            pl();
        }
    }
    static void pa(String arrayName, char[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(char o : arr[i])
                p(o);
            pl();
        }
    }
    static void pa(String arrayName, double[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(double o : arr[i])
                p(o);
            pl();
        }
    }
    static class MyScanner
    {
        BufferedReader br;
        StringTokenizer st;
        MyScanner(boolean readingFromFile) throws IOException
        {
            if(readingFromFile) {
                br = new BufferedReader(new FileReader("/Users/amandeep/Desktop/input.txt"));
            }
            else {
                br = new BufferedReader(new InputStreamReader(System.in));
            }
        }
        String nextLine()throws IOException
        {
            return br.readLine();
        }
        String next() throws IOException
        {
            if(st==null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }
        int nextInt() throws IOException
        {
            return Integer.parseInt(next());
        }
        long nextLong() throws IOException
        {
            return Long.parseLong(next());
        }
        double nextDouble() throws IOException
        {
            return Double.parseDouble(next());
        }
    }
}