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.HashSet;
import java.util.Arrays;
import java.util.Collection;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Queue;
import java.util.LinkedList;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author beginner1010
 */
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 {
        final int MAX_BIT = 65;
        ArrayList<Integer>[] nodes;
        ArrayList<Integer>[] adj;
        int[] distance;
        boolean[] visited;

        long two(int bit) {
            return 1L << bit;
        }

        boolean contain(long mask, int bit) {
            return (mask & two(bit)) > 0;
        }

        int bfs(int a, int b) {
            int start = a;
            Queue<Integer> q = new LinkedList<>();
            q.add(start);
            distance[start] = 0;
            visited[start] = true;
            HashSet<Integer> seen = new HashSet<>();
            while (!q.isEmpty()) {
                int cur = q.poll();
                seen.add(cur);
                for (int i = 0; i < adj[cur].size(); i++) {
                    int neighbor = adj[cur].get(i);
                    if ((a == cur && b == neighbor) || (b == cur && a == neighbor))
                        continue;
                    if (visited[neighbor] == true)
                        continue;
                    visited[neighbor] = true;
                    distance[neighbor] = distance[cur] + 1;
                    q.add(neighbor);
                }
            }
            int ans = distance[b];
            for (int seenNode : seen) {
                visited[seenNode] = false;
                distance[seenNode] = -1;
            }
            return ans;
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            nodes = new ArrayList[MAX_BIT];
            for (int i = 0; i < MAX_BIT; i++) {
                nodes[i] = new ArrayList<>();
            }

            int n = in.nextInt();
            long[] nodeID = new long[n];
            boolean cycleThree = false;
            for (int i = 0; i < n; i++) {
                nodeID[i] = in.nextLong();
                for (int j = 0; j < MAX_BIT; j++) {
                    if (contain(nodeID[i], j) == true) {
                        nodes[j].add(i);
                        if (nodes[j].size() >= 3) {
                            cycleThree = true;
                            break;
                        }
                    }
                }
                if (cycleThree == true)
                    break;
            }

            if (cycleThree == true) {
                out.println("3");
            } else {
                adj = new ArrayList[n];
                for (int i = 0; i < n; i++) {
                    adj[i] = new ArrayList<>();
                    HashSet<Integer> set = new HashSet<>();
                    for (int j = 0; j < MAX_BIT; j++) {
                        if (contain(nodeID[i], j) == true) {
                            for (int neighborID : nodes[j]) {
                                if (neighborID == i)
                                    continue;
                                set.add(neighborID);
                            }
                        }
                    }
                    assert (set.size() < MAX_BIT);
                    for (int neighborID : set) {
                        adj[i].add(neighborID);
                    }
                }

                visited = new boolean[n];
                distance = new int[n];
                Arrays.fill(distance, -1);
                int ans = MAX_BIT;
                for (int i = 0; i < n; i++) {
                    for (int neighbor : adj[i]) {
                        int shortedCycle = bfs(i, neighbor);
                        if (shortedCycle != -1)
                            ans = Math.min(ans, shortedCycle + 1);
                    }
                }
                if (ans == MAX_BIT)
                    ans = -1;
                out.println(ans);
            }
        }

    }

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

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

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

        private 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 nextInt() {
            int c = read();
            while (isWhitespace(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 (!isWhitespace(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isWhitespace(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 (!isWhitespace(c));
            return res * sgn;
        }

    }
}

