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.OutputStream;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.Set;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.BufferedOutputStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Objects;
import java.util.List;
import java.io.Closeable;
import java.io.Writer;
import java.util.Queue;
import java.util.ArrayDeque;
import java.io.InputStream;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author MaxHeap
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    OutputWriter out = new OutputWriter(outputStream);
    DShortestCycle solver = new DShortestCycle();
    solver.solve(1, in, out);
    out.close();
  }

  static class DShortestCycle {

    List<Integer>[] g;
    Set<DShortestCycle.IntPair> edges;
    int ans = Integer.MAX_VALUE;

    public void solve(int testNumber, InputReader in, OutputWriter out) {
      int n = in.nextInt();
      long[] a = in.nextLongArray(n);
      List<Integer>[] was = createGraph(64);
      for (int i = 0; i < 63; ++i) {
        for (int j = 0; j < n; ++j) {
          if ((a[j] & (1L << i)) > 0) {
            was[i].add(j);
          }
        }
      }
      edges = new HashSet<>();
      for (int i = 0; i < 64; ++i) {
        if (was[i].size() == 2) {
          addEdge(was[i].get(0), was[i].get(1));
        } else if (was[i].size() >= 3) {
          out.println(3);
          return;
        }
      }
      g = createGraph(n);
      for (DShortestCycle.IntPair edge : edges) {
        g[edge.f].add(edge.s);
        g[edge.s].add(edge.f);
      }

      Queue<Integer> q = new ArrayDeque<>();
      int[] par = new int[n];
      int[] dist = new int[n];

      for (int i = 0; i < n; ++i) {
        if (g[i].isEmpty()) {
          continue;
        }
        q.clear();
        ArrayUtils.fill(par, -1);
        ArrayUtils.fill(dist, 1 << 30);
        dist[i] = 0;
        q.add(i);
        while (!q.isEmpty()) {
          int u = q.poll();
          for (int v : g[u]) {
            if (dist[v] > 1e9) {
              dist[v] = dist[u] + 1;
              par[v] = u;
              q.add(v);
            } else if (par[v] != u && par[u] != v) {
              ans = Math.min(ans, dist[u] + dist[v] + 1);
            }
          }
        }
      }
      out.println(ans > 1e9 ? -1 : ans);
    }

    private void addEdge(int u, int v) {
      edges.add(DShortestCycle.IntPair.createNormalized(u, v));
    }

    List<Integer>[] createGraph(int n) {
      List<Integer>[] was = new ArrayList[n];
      for (int i = 0; i < was.length; ++i) {
        was[i] = new ArrayList<>();
      }
      return was;
    }

    static class IntPair {

      int f;
      int s;

      public IntPair(int f, int s) {
        this.f = f;
        this.s = s;
      }

      public static DShortestCycle.IntPair createNormalized(int f, int s) {
        return new DShortestCycle.IntPair(Math.min(f, s), Math.max(f, s));
      }

      public boolean equals(Object o) {
        if (this == o) {
          return true;
        }
        if (o == null || getClass() != o.getClass()) {
          return false;
        }
        DShortestCycle.IntPair intPair = (DShortestCycle.IntPair) o;
        return f == intPair.f &&
            s == intPair.s;
      }

      public int hashCode() {
        return Objects.hash(f, s);
      }

    }

  }

  static class ArrayUtils {

    public static void fill(int[] a, int val) {
      for (int i = 0; i < a.length; i++) {
        a[i] = val;
      }
    }

  }

  static class InputReader {

    private InputStream stream;
    private static final int DEFAULT_BUFFER_SIZE = 1 << 16;
    private static final int EOF = -1;
    private byte[] buf = new byte[DEFAULT_BUFFER_SIZE];
    private int curChar;
    private int numChars;

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

    public int read() {
      if (this.numChars == EOF) {
        throw new UnknownError();
      } else {
        if (this.curChar >= this.numChars) {
          this.curChar = 0;

          try {
            this.numChars = this.stream.read(this.buf);
          } catch (IOException ex) {
            throw new InputMismatchException();
          }

          if (this.numChars <= 0) {
            return EOF;
          }
        }

        return this.buf[this.curChar++];
      }
    }

    public int nextInt() {
      int c;
      for (c = this.read(); isSpaceChar(c); c = this.read()) {
      }

      byte sgn = 1;
      if (c == 45) {
        sgn = -1;
        c = this.read();
      }

      int res = 0;

      while (c >= 48 && c <= 57) {
        res *= 10;
        res += c - 48;
        c = this.read();
        if (isSpaceChar(c)) {
          return res * sgn;
        }
      }

      throw new InputMismatchException();
    }

    public long nextLong() {
      int c;
      for (c = this.read(); isSpaceChar(c); c = this.read()) {
      }

      byte sgn = 1;
      if (c == 45) {
        sgn = -1;
        c = this.read();
      }

      long res = 0;

      while (c >= 48 && c <= 57) {
        res *= 10L;
        res += c - 48;
        c = this.read();
        if (isSpaceChar(c)) {
          return res * sgn;
        }
      }
      throw new InputMismatchException();
    }

    public static boolean isSpaceChar(int c) {
      return c == 32 || c == 10 || c == 13 || c == 9 || c == EOF;
    }

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

  }

  static class OutputWriter implements Closeable {

    private PrintWriter out;

    public OutputWriter(OutputStream os) {
      out = new PrintWriter(new BufferedOutputStream(os, 1 << 16));
    }

    public OutputWriter(Writer writer) {
      out = new PrintWriter(writer);
    }

    public void println(int x) {
      out.println(x);
    }

    public void close() {
      if (out != null) {
        out.close();
      }
    }

  }
}

