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.PriorityQueue;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.AbstractCollection;
import java.util.Vector;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.LinkedList;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author xwchen
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(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, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            long[] a = in.nextLongArray(n);
            int ans = -1;
            for (int pos = 0; pos < 61; ++pos) {
                int cnt = 0;
                for (int i = 0; i < n; ++i) {
                    if (BitUtil.testBit(a[i], pos)) {
                        ++cnt;
                    }
                }
                if (cnt >= 3) {
                    ans = 3;
                }
            }
            if (ans == 3) {
                out.println(3);
            } else {
                Graph g = new Graph(n);
                for (int i = 0; i < 61; ++i) {
                    Vector<Integer> nodes = new Vector<>();
                    for (int j = 0; j < n; ++j) {
                        if (BitUtil.testBit(a[j], i)) {
                            nodes.add(j);
                        }
                    }
                    for (int j = 0; j < nodes.size(); ++j) {
                        for (int k = j + 1; k < nodes.size(); ++k) {
                            if (!g.isContainsEdge(nodes.get(j), nodes.get(k))) {
                                g.addEdge(nodes.get(j), nodes.get(k), 1);
                            }
                        }
                    }
                }
                long minDistance = 1000000000;
                for (int i = 0; i < n; ++i) {
                    if (!g.adj[i].isEmpty()) {
                        for (Graph.Edge e : g.adj[i]) {
                            int j = e.v;
                            if (j < i) continue;
                            e.enable = false;
                            Graph.Edge eV = null;
                            for (Graph.Edge e2 : g.adj[j]) {
                                if (e2.v == i) {
                                    eV = e2;
                                    e2.enable = false;
                                    break;
                                }
                            }
                            long dis = g.getMinDistanceBetween(i, j);
                            e.enable = true;
                            eV.enable = true;
                            if (dis != -1) {
                                minDistance = Math.min(minDistance, dis);
                            }
                        }
                    }
                }
                if (minDistance != 1000000000) {
                    out.println(minDistance + 1);
                } else {
                    out.println(-1);
                }
            }
        }

    }

    static class BitUtil {
        public static boolean testBit(long mask, int pos) {
            return (mask & (1L << pos)) != 0;
        }

    }

    static class Graph {
        public LinkedList<Edge>[] adj;
        int n;

        public Graph() {

        }

        public Graph(int n) {
            this.n = n;
            adj = new LinkedList[n + 1];
            for (int i = 0; i <= n; ++i) {
                adj[i] = new LinkedList<>();
            }
        }

        public boolean isContainsEdge(int u, int v) {
            for (Edge e : adj[u]) {
                if (e.v == v) {
                    return true;
                }
            }
            return false;
        }

        public void addEdge(int u, int v, int value) {
            adj[u].add(new Edge(v, value));
            adj[v].add(new Edge(u, value));
            //System.out.println("add edge "+u+" "+v);
        }

        public long getMinDistanceBetween(int u, int v) {
            PriorityQueue<Node> pq = new PriorityQueue<>(Comparator.comparingInt(x -> x.distance));
            Node p = new Node(u, 0);
            boolean[] vis = new boolean[n + 1];
            pq.add(p);
            while (!pq.isEmpty()) {
                Node cur = pq.poll();
                if (cur.u == v) {
                    return cur.distance;
                }
                for (Edge e : adj[cur.u]) {
                    if (!vis[e.v] && e.enable) {
                        vis[e.v] = true;
                        pq.add(new Node(e.v, cur.distance + e.value));
                    }
                }
            }
            return -1;
        }

        public class Edge {
            public int u;
            public int v;
            public int value;
            public boolean enable = true;

            public Edge(int u, int v, int value) {
                this.u = u;
                this.v = v;
                this.value = value;
            }

            public Edge(int v, int value) {
                this.v = v;
                this.value = value;
            }

        }

        class Node {
            int u;
            int distance;

            public Node(int u, int distance) {
                this.u = u;
                this.distance = distance;
            }

        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer = new StringTokenizer("");

        public InputReader(InputStream inputStream) {
            this.reader = new BufferedReader(
                    new InputStreamReader(inputStream));
        }

        public String next() {
            while (!tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return tokenizer.nextToken();
        }

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

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

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }

    }
}

