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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextLong();
            }

            final int BITS = 62;
            List<Integer>[] withBit = new List[BITS];
            for (int bit = 0; bit < BITS; bit++) {
                withBit[bit] = new ArrayList<>();
                for (int i = 0; i < n; i++) {
                    if ((a[i] & (1L << bit)) > 0) {
                        withBit[bit].add(i);
                    }
                }
                if (withBit[bit].size() > 3) {
                    out.println(3);
                    return;
                }
            }

            Graph g = new Graph(n);
            for (int bit = 0; bit < BITS; bit++) {
                for (int i = 0; i < withBit[bit].size(); i++) {
                    for (int j = i + 1; j < withBit[bit].size(); j++) {
                        int u = withBit[bit].get(i);
                        int v = withBit[bit].get(j);
                        g.addEdge(u, v);
                        g.addEdge(v, u);
                    }
                }
            }
            int ans = n + 1;
            for (int i = 0; i < n; i++) {
                for (int e = g.firstEdge[i]; e >= 0; e = g.edgeNxt[e]) {
                    int j = g.edgeDst[e];
                    int[] d = bfs(i, g, i, j);
                    ans = Math.min(ans, d[j] + 1);
                }
            }
            if (ans == n + 1) {
                ans = -1;
            }
            out.println(ans);
        }

        private int[] bfs(int s, Graph g, int forbiddenA, int forbiddenB) {
            int[] q = new int[g.n];
            int[] d = new int[g.n];
            Arrays.fill(d, g.n);
            d[s] = 0;
            q[0] = s;
            int qt = 0;
            int qh = 1;
            while (qt < qh) {
                int x = q[qt++];
                for (int e = g.firstEdge[x]; e >= 0; e = g.edgeNxt[e]) {
                    int y = g.edgeDst[e];
                    if (x == forbiddenA && y == forbiddenB) {
                        continue;
                    }
                    if (x == forbiddenB && y == forbiddenA) {
                        continue;
                    }
                    if (d[y] > 1 + d[x]) {
                        d[y] = 1 + d[x];
                        q[qh++] = y;
                    }
                }
            }
            return d;
        }

        class Graph {
            int[] firstEdge;
            int[] edgeNxt;
            int[] edgeDst;
            int numEdges;
            int n;

            Graph(int n) {
                this.n = n;
                firstEdge = new int[n];
                Arrays.fill(firstEdge, -1);
                final int initialCapacity = 10;
                edgeNxt = new int[initialCapacity];
                edgeDst = new int[initialCapacity];
                numEdges = 0;
            }

            public void addEdge(int a, int b) {
                int e = numEdges++;
                if (e >= edgeNxt.length) {
                    reallocate();
                }
                edgeNxt[e] = firstEdge[a];
                edgeDst[e] = b;
                firstEdge[a] = e;
            }

            private void reallocate() {
                int k = edgeNxt.length;
                k = 3 * k / 2;
                edgeNxt = Arrays.copyOf(edgeNxt, k);
                edgeDst = Arrays.copyOf(edgeDst, k);
            }

        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}

