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.Collection;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.math.BigInteger;
import java.util.Queue;
import java.util.ArrayDeque;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Kirill Antonov
 */
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);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.readInt();
            long[] a = in.readLongArray(n);
            ArrayList<ArrayList<Integer>> indexesOfThatOne = new ArrayList<>(60);
            for (int i = 0; i < 60; i++) {
                indexesOfThatOne.add(new ArrayList<>());
            }
            for (int i1 = 0; i1 < a.length; i1++) {
                long ai = a[i1];
                BigInteger bigInteger = BigInteger.valueOf(ai);
                String binRepr = bigInteger.toString(2);
                if (binRepr.length() < 60) {
                    StringBuilder zerosBuilder = new StringBuilder();
                    for (int i = 0; i < 60 - binRepr.length(); i++) {
                        zerosBuilder.append('0');
                    }
                    String zeros = zerosBuilder.toString();
                    binRepr = zeros + binRepr;
                }
                for (int i = 0; i < binRepr.length(); i++) {
                    char c = binRepr.charAt(i);
                    int value = c - '0';
                    if (value == 1) {
                        indexesOfThatOne.get(i).add(i1);
                    }
                }
            }
            int ans = Integer.MAX_VALUE;
            HashMap<Integer, HashSet<Integer>> graph = new HashMap<>(120);
            for (ArrayList<Integer> ones : indexesOfThatOne) {
                if (ones.size() > 2) {
                    ans = 3;
                    printAns(out, ans);
                    return;
                }
                if (ones.size() == 1) {
                    handleSize1(graph, ones);
                }
                if (ones.size() == 2) {
                    handleSize2(graph, ones);
                }
            }

            for (Edge edge : getAllEdgesList(graph)) {
                removeEdgeFromGraph(graph, edge);
                ans = Math.min(ans, findDistanceBetweenNodes(graph, edge.u, edge.v) + 1);
                addEdgeToGraph(graph, edge.u, edge.v);
            }
            printAns(out, ans);
        }

        private void removeEdgeFromGraph(HashMap<Integer, HashSet<Integer>> graph, Edge edge) {
            if (!graph.containsKey(edge.u)) {
                return;
            }
            assert graph.containsKey(edge.v);
            graph.get(edge.u).remove(edge.v);
            graph.get(edge.v).remove(edge.u);
        }

        private ArrayList<Edge> getAllEdgesList(HashMap<Integer, HashSet<Integer>> graph) {
            ArrayList<Edge> allEdges = new ArrayList<>(graph.size() * 2);
            HashMap<Integer, Boolean> was = new HashMap<>(graph.size());
            for (Integer u : graph.keySet()) {
                was.put(u, false);
            }
            for (Integer u : graph.keySet()) {
                HashSet<Integer> adjacentNodes = graph.get(u);
                for (Integer v : adjacentNodes) {
                    if (!was.get(v)) {
                        allEdges.add(new Edge(u, v));
                    }
                }
                was.put(u, true);
            }
            return allEdges;
        }

        private int findDistanceBetweenNodes(HashMap<Integer, HashSet<Integer>> graph, Integer u, Integer v) {
            Queue<Integer> queue = new ArrayDeque<>();
            queue.add(u);
            HashMap<Integer, Integer> shortestPathLength = new HashMap<>(graph.size());
            for (Integer node : graph.keySet()) {
                shortestPathLength.put(node, -1);
            }
            shortestPathLength.put(u, 0);
            while (!queue.isEmpty()) {
                Integer curNode = queue.poll();
                int distanceToNext = shortestPathLength.get(curNode) + 1;
                for (Integer adjacentNode : graph.get(curNode)) {
                    int dist = shortestPathLength.get(adjacentNode);
                    if (dist == -1) {
                        shortestPathLength.put(adjacentNode, distanceToNext);
                        queue.add(adjacentNode);
                    }
                    if (v.equals(adjacentNode)) {
                        return shortestPathLength.get(v);
                    }
                }
            }
            return Integer.MAX_VALUE - 1;
        }

        private void handleSize1(HashMap<Integer, HashSet<Integer>> graph, ArrayList<Integer> ones) {
            Integer index = ones.get(0);
            graph.putIfAbsent(index, new HashSet<>());
        }

        private void handleSize2(HashMap<Integer, HashSet<Integer>> graph, ArrayList<Integer> ones) {
            Integer index1 = ones.get(0);
            Integer index2 = ones.get(1);
            addEdgeToGraph(graph, index1, index2);
        }

        private void addEdgeToGraph(HashMap<Integer, HashSet<Integer>> graph, Integer index1, Integer index2) {
            graph.putIfAbsent(index1, new HashSet<>());
            graph.get(index1).add(index2);
            graph.putIfAbsent(index2, new HashSet<>());
            graph.get(index2).add(index1);
        }

        private void printAns(PrintWriter out, int ans) {
            if (ans == Integer.MAX_VALUE) {
                out.println(-1);
            } else {
                out.println(ans);
            }
        }

        private class Edge {
            int u;
            int v;

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

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long readLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * (long) sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public long[] readLongArray(int size) {
            long[] array = new long[size];
            for (int i = 0; i < size; i++) {
                array[i] = readLong();
            }
            return array;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

