Limits
3s, 1.0 GB

Alice has found an array $A$ containing $n$ non-negative integers, where the $i$-th element is named $A_i$. But she only likes an array if all elements of it are equal.

In order to make Alice happy, Bob has come up with an idea. He has a small array $B$ with $m$ non-negative integers, where the $j$-th element is named $B_j$. Bob can do the following operation any number of times (possibly zero):

Select any integer $k$ where $1 \leq k \leq n$.

Select any subset $S$ containing $k$ distinct indices of $A$. Let $S = \{s_1, s_2, s_3, ..., s_k\}$.

Select any integer $x \in B$.

For each element $s_i \in S$, assign $A_{s_i} := A_{s_i} \oplus x$.

However, because doing this operation requires so much energy, Bob asked you to determine the minimum number of operations required to make all elements of $A$ equal or report if it is impossible. Can you make both Alice and Bob happy?

The input contains three lines.

The first line contains two integers $n$ $(1 \leq n \leq 10^5)$ and $m$ $(1 \leq m \leq 24)$.

The second line contains $n$ integers representing $A$ where the $i$-th integer represents $A_i$ $(0 \leq A_i < 2^{24})$.

The third line contains $m$ integers representing $B$ where the $j$-th integer represents $B_j$ $(0 \leq B_j < 2^{24})$.

Print an integer in a single line denoting the minimum number of operations required to make all elements of $A$ equal if it is possible, otherwise print $-1$.

Input | Output |
---|---|

3 2 1 3 5 6 2 | 2 |

Input | Output |
---|---|

2 1 1 4 2 | -1 |